https://kotlinlang.org logo
#reflect
Title
# reflect
s

SrSouza

11/01/2018, 2:56 PM
Hi, I update my project to Kotlin 1.3.0 but the same code in 1.2.60 is giving me a error on 1.3.0
Copy code
[11:53:05 ERROR]: Error occurred while enabling KotlinBukkitAPI v0.1.0-SNAPSHOT (Is it up to date?)
java.lang.IllegalAccessError: tried to access method kotlin.collections.ArraysKt___ArraysJvmKt.copyOfRange([Ljava/lang/Object;II)[Ljava/lang/Object; from class kotlin.reflect.jvm.internal.calls.CallerImpl$Method$Instance
	at kotlin.reflect.jvm.internal.calls.CallerImpl$Method$Instance.call(CallerImpl.kt:217) ~[?:?]
	at kotlin.reflect.jvm.internal.KCallableImpl.call(KCallableImpl.kt:106) ~[?:?]
	at kotlin.reflect.jvm.internal.KMutableProperty1Impl.set(KProperty1Impl.kt:59) ~[?:?]
	at br.com.devsrsouza.kotlinbukkitapi.dsl.config.KConfig.loadRecursive(ConfigDSL.kt:392) ~[?:?]
	at br.com.devsrsouza.kotlinbukkitapi.dsl.config.KConfig.loadAndSetDefaultR(ConfigDSL.kt:142) ~[?:?]
	at br.com.devsrsouza.kotlinbukkitapi.dsl.config.KConfig.loadAndSetDefault(ConfigDSL.kt:96) ~[?:?]
	at br.com.devsrsouza.kotlinbukkitapi.dsl.config.ConfigDSLKt.loadAndSetDefault(ConfigDSL.kt:63) ~[?:?]
	at br.com.devsrsouza.kotlinbukkitapi.dsl.config.ConfigDSLKt.loadAndSetDefault$default(ConfigDSL.kt:61) ~[?:?]
	at br.com.devsrsouza.kotlinbukkitapi.KotlinBukkitAPI.onEnable(KotlinBukkitAPI.kt:25) ~[?:?]
	at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:321) ~[1.8.8.jar:git-Spigot-21fe707-e1ebe52]
	at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:340) ~[1.8.8.jar:git-Spigot-21fe707-e1ebe52]
	at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:405) ~[1.8.8.jar:git-Spigot-21fe707-e1ebe52]
	at br.com.devsrsouza.pluginlauncher.Main.lambda$onEnable$0(Main.java:32) ~[?:?]
	at org.bukkit.craftbukkit.v1_8_R3.scheduler.CraftTask.run(CraftTask.java:71) [1.8.8.jar:git-Spigot-21fe707-e1ebe52]
	at org.bukkit.craftbukkit.v1_8_R3.scheduler.CraftScheduler.mainThreadHeartbeat(CraftScheduler.java:350) [1.8.8.jar:git-Spigot-21fe707-e1ebe52]
	at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:723) [1.8.8.jar:git-Spigot-21fe707-e1ebe52]
	at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:374) [1.8.8.jar:git-Spigot-21fe707-e1ebe52]
	at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:654) [1.8.8.jar:git-Spigot-21fe707-e1ebe52]
	at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:557) [1.8.8.jar:git-Spigot-21fe707-e1ebe52]
	at java.lang.Thread.run(Thread.java:748) [?:1.8.0_181]
i

ilya.gorbunov

11/01/2018, 3:25 PM
What is the version of
kotlin-reflect
library that you're actually using at run time?
s

SrSouza

11/01/2018, 3:29 PM
i'm using Gradle Kotlin DSL, the version of the project is 1.3.0, i think its using the same version because that
Copy code
kotlin
plugins {
    kotlin("jvm") version "1.3.0"
    .....
}
....
dependencies {
   ......
    compile(kotlin("reflect"))
}
I made a test, just downgrading the version to 1.2.60, this exception don't appear
i

ilya.gorbunov

11/01/2018, 3:45 PM
It looks like you're compiling your code against
kotlin-stdlib:1.3.0
but using
kotlin-stdlib:1.2.x
in runtime.
s

SrSouza

11/01/2018, 5:02 PM
I made a test, running in IDEA its okay, but running in the jar is not working I use shadow plugin to add the kotlin stdlib and reflect. The thing I don't understand is why 1.2.60 works fine, but 1.3.0 keep giving me this error 🤔 The test I made
Copy code
kotlin
fun main() {
    for (prop in test::class.memberProperties.filterIsInstance<KMutableProperty1<Any, Any>>()) {
        if(prop.name.equals("texto", true)) {
            println("ehnois")
            prop.set(test, "something")
        }
    }
    println(test)
}

object test {
    var texto = "aaaa"
    var id = 15152063
    override fun toString(): String {
        return "test(texto='$texto', id=$id)"
    }
}
Same error in
prop.set
i

ilya.gorbunov

11/01/2018, 6:14 PM
1.2.60 works fine because
kotlin-reflect:1.2.60
works fine with
kotlin-stdlib:1.2.60
and
kotlin-reflect:1.3.0
doesn't — it requires
kotlin-stdlib:1.3.0
in runtime. Is this test enough to reproduce the problem or some special setup is needed?
s

SrSouza

11/01/2018, 6:24 PM
Is enough to reproduce the problem only on running in the jar, in IDEA works fine My gradle build script
Copy code
kotlin
plugins {
    id("java")
    id("maven-publish")
    kotlin("jvm") version "1.3.0"
    id("com.github.johnrengelman.shadow") version "4.0.2"
}

dependencies {
    compile(kotlin("stdlib", "1.3.0"))
    compile("org.jetbrains.kotlin:kotlin-reflect:1.3.0")
    //compile(kotlin("reflect", "1.3.0")) this is working too
    compile("com.comphenix.attribute:AttributeStorage:0.0.2-SNAPSHOT")
}

tasks {
    "compileKotlin"(KotlinCompile::class) {
        kotlinOptions {
            jvmTarget = "1.8"
        }
    }
    "shadowJar"(ShadowJar::class) {
        baseName = project.name
        classifier = null
        dependencies {
            include(dependency("org.jetbrains.kotlin:kotlin-stdlib:1.3.0"))
            include(dependency("org.jetbrains.kotlin:kotlin-reflect:1.3.0"))
            include(dependency("com.comphenix.attribute:AttributeStorage:0.0.2-SNAPSHOT"))
        }
    }
}
Tkx for the help, is exacly what you say, is 1.2, but is not in my project, is in other project running together with mine. Tkx so much for the help, sorry for wasting your time ❤️
j

jdiaz

11/01/2018, 7:32 PM
If you don't input the version when you input the
compile(kotlin-reflect)
it'll use the version from your IDE iirc, so by just adding the version explicitly it's fine. It should also work by updating the version in the IDE (I had this problem too)
4 Views