I searched for how you create 2D array in Kotlin and found something like val array = Array(2, {IntArray(2)}) while this compiles just fine using kotlinc test.kt -include-runtime -d test.jar, running it using java -jar test.jar throws java.lang.NullPointerException. After this I tried with Kotlin Playground for which it worked just fine. According to that there should not be anything wrong with the code. I'm not sure if this is because of there is some bug in command line tool or in my Java, I'm using openjdk 1.8.0_181-b13 on Arch Linux, I also tried openjdk10 with same problem. Any idea why this happens?
// test.kt
fun main(args: Array<String>) {
val array = Array(2, {IntArray(2)})
}
If I compile with kotlinc test.kt and run kotlin TestKt I get:
Exception in thread "main" java.lang.NullPointerException
at TestKt.main(test.kt:2)
at sun.reflect.NativeMethodAccessorImpl.incoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethdoAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.jetbrains.kotlin.runner.AbstractRunner.run(runners.kt:61)
at org.jetbrains.kotlin.runner.Main.run(Main.kt:109)
at org.jetbrains.kotlin.runner.Main.main(Main.kt:119)
edit: I found out that problem was in compilation process and tried installing compiler with SKDMAN! instead of installing binaries which seemed to work.