Static initializer bug


#1

 

fun main(args: Array<String>) {
  println(A.a)

}

class A{
  class object{
  val a: Int
  {
  a = 0
  }
  }
}

It compiles but throws

Exception in thread “main” java.lang.NoSuchFieldError: a
  at net.unitcraft.content.A.<clinit>(Main.kt:19)
  at net.unitcraft.content.ContentPackage-Main-c1ee52f.main(Main.kt:11)
  at net.unitcraft.content.ContentPackage.main(Main.kt:1)
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  at java.lang.reflect.Method.invoke(Method.java:483)
  at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)

I use Idea 138.1503.3.


#2

Your version of Kotlin would be of much use to us. Thanks


#3

I dont understand your answer. My english is poor. This bug already fixed in another version of Kotlin? Or this is not bug?


#4

Please reply with your version of Kotlin plugin. You can find it in Preferences, in Plugins section, find Kotlin, version is right below the Uninstall button.


#5

Kotlin plugin 0.8.11.1


#6

This bug affects only class object fields that initialized in anonymous initializer. As a temporary workaround move field intializer directly to field:

class A{
    class object{
        val a: Int = 0
    }
}

#7

This bug is already in our tracker (KT-4206), thank you.