Skip to content

Instantly share code, notes, and snippets.

@jrenner
Last active January 1, 2016 12:09
Show Gist options
  • Save jrenner/8142208 to your computer and use it in GitHub Desktop.
Save jrenner/8142208 to your computer and use it in GitHub Desktop.
fun main(args: Array<String>) {
val arr = array("cats", "dogs")
for (i in 0..10) {
println(arr.random())
}
// this version works fine
fun <T> Array<T>.random() : T {
val rand = Random()
return this.get(rand.nextInt(this.size))
}
// infix version causes compiler error
fun <T> Array<T>.random() : T {
val rand = Random()
return this get rand.nextInt(this.size)
}
// error message
Kotlin: [Internal Error] org.jetbrains.jet.codegen.CompilationException: Back-end (JVM) Internal error: null
Cause: java.lang.NullPointerException
File being compiled and position: (38,12) in /home/jrenner/test-kotlin/src/org/jrenner/test/Main.kt
PsiElement: this get rand.nextInt(this.size)
The root cause was thrown at: String.java:200
at org.jetbrains.jet.codegen.ExpressionCodegen.genQualified(ExpressionCodegen.java:245)
at org.jetbrains.jet.codegen.ExpressionCodegen.genQualified(ExpressionCodegen.java:216)
at org.jetbrains.jet.codegen.ExpressionCodegen.gen(ExpressionCodegen.java:251)
at org.jetbrains.jet.codegen.ExpressionCodegen.gen(ExpressionCodegen.java:255)
at org.jetbrains.jet.codegen.ExpressionCodegen.visitReturnExpression(ExpressionCodegen.java:1570)
at org.jetbrains.jet.codegen.ExpressionCodegen.visitReturnExpression(ExpressionCodegen.java:81)
at org.jetbrains.jet.lang.psi.JetReturnExpression.accept(JetReturnExpression.java:35)
at org.jetbrains.jet.codegen.ExpressionCodegen.genQualified(ExpressionCodegen.java:235)
at org.jetbrains.jet.codegen.ExpressionCodegen.genQualified(ExpressionCodegen.java:216)
at org.jetbrains.jet.codegen.ExpressionCodegen.gen(ExpressionCodegen.java:251)
at org.jetbrains.jet.codegen.ExpressionCodegen.generateBlock(ExpressionCodegen.java:1421)
at org.jetbrains.jet.codegen.ExpressionCodegen.visitBlockExpression(ExpressionCodegen.java:1280)
at org.jetbrains.jet.codegen.ExpressionCodegen.visitBlockExpression(ExpressionCodegen.java:81)
at org.jetbrains.jet.lang.psi.JetBlockExpression.accept(JetBlockExpression.java:47)
at org.jetbrains.jet.codegen.ExpressionCodegen.genQualified(ExpressionCodegen.java:235)
at org.jetbrains.jet.codegen.ExpressionCodegen.genQualified(ExpressionCodegen.java:216)
at org.jetbrains.jet.codegen.ExpressionCodegen.gen(ExpressionCodegen.java:251)
at org.jetbrains.jet.codegen.ExpressionCodegen.returnExpression(ExpressionCodegen.java:1582)
at org.jetbrains.jet.codegen.FunctionGenerationStrategy$FunctionDefault.doGenerateBody(FunctionGenerationStrategy.java:70)
at org.jetbrains.jet.codegen.FunctionGenerationStrategy$CodegenBased.generateBody(FunctionGenerationStrategy.java:92)
at org.jetbrains.jet.codegen.FunctionCodegen.generateMethodBody(FunctionCodegen.java:289)
at org.jetbrains.jet.codegen.FunctionCodegen.generateMethod(FunctionCodegen.java:144)
at org.jetbrains.jet.codegen.FunctionCodegen.generateMethod(FunctionCodegen.java:97)
at org.jetbrains.jet.codegen.FunctionCodegen.gen(FunctionCodegen.java:83)
at org.jetbrains.jet.codegen.MemberCodegen.genFunctionOrProperty(MemberCodegen.java:47)
at org.jetbrains.jet.codegen.NamespacePartCodegen.generate(NamespacePartCodegen.java:84)
at org.jetbrains.jet.codegen.NamespaceCodegen.generate(NamespaceCodegen.java:191)
at org.jetbrains.jet.codegen.NamespaceCodegen.generate(NamespaceCodegen.java:113)
at org.jetbrains.jet.codegen.KotlinCodegenFacade.generateNamespace(KotlinCodegenFacade.java:71)
at org.jetbrains.jet.codegen.KotlinCodegenFacade.compileCorrectFiles(KotlinCodegenFacade.java:60)
at org.jetbrains.jet.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.generate(KotlinToJVMBytecodeCompiler.java:304)
at org.jetbrains.jet.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.analyzeAndGenerate(KotlinToJVMBytecodeCompiler.java:262)
at org.jetbrains.jet.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.compileModule(KotlinToJVMBytecodeCompiler.java:104)
at org.jetbrains.jet.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.compileModules(KotlinToJVMBytecodeCompiler.java:140)
at org.jetbrains.jet.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.java:132)
at org.jetbrains.jet.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.java:48)
at org.jetbrains.jet.cli.common.CLICompiler.exec(CLICompiler.java:152)
at org.jetbrains.jet.cli.common.CLICompiler.exec(CLICompiler.java:138)
at org.jetbrains.jet.cli.common.CLICompiler.exec(CLICompiler.java:57)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.jetbrains.jet.compiler.runner.CompilerRunnerUtil.invokeExecMethod(CompilerRunnerUtil.java:121)
at org.jetbrains.jet.compiler.runner.KotlinCompilerRunner.execCompiler(KotlinCompilerRunner.java:111)
at org.jetbrains.jet.compiler.runner.KotlinCompilerRunner.access$000(KotlinCompilerRunner.java:39)
at org.jetbrains.jet.compiler.runner.KotlinCompilerRunner$1.fun(KotlinCompilerRunner.java:94)
at org.jetbrains.jet.compiler.runner.KotlinCompilerRunner$1.fun(KotlinCompilerRunner.java:91)
at org.jetbrains.jet.compiler.runner.CompilerRunnerUtil.outputCompilerMessagesAndHandleExitCode(CompilerRunnerUtil.java:130)
at org.jetbrains.jet.compiler.runner.KotlinCompilerRunner.runCompiler(KotlinCompilerRunner.java:91)
at org.jetbrains.jet.compiler.runner.KotlinCompilerRunner.runK2JvmCompiler(KotlinCompilerRunner.java:57)
at org.jetbrains.jet.jps.build.KotlinBuilder.build(KotlinBuilder.java:168)
at org.jetbrains.jps.incremental.IncProjectBuilder.runModuleLevelBuilders(IncProjectBuilder.java:1086)
at org.jetbrains.jps.incremental.IncProjectBuilder.runBuildersForChunk(IncProjectBuilder.java:797)
at org.jetbrains.jps.incremental.IncProjectBuilder.buildTargetsChunk(IncProjectBuilder.java:845)
at org.jetbrains.jps.incremental.IncProjectBuilder.buildChunkIfAffected(IncProjectBuilder.java:760)
at org.jetbrains.jps.incremental.IncProjectBuilder.buildChunks(IncProjectBuilder.java:583)
at org.jetbrains.jps.incremental.IncProjectBuilder.runBuild(IncProjectBuilder.java:344)
at org.jetbrains.jps.incremental.IncProjectBuilder.build(IncProjectBuilder.java:184)
at org.jetbrains.jps.cmdline.BuildRunner.runBuild(BuildRunner.java:129)
at org.jetbrains.jps.cmdline.BuildSession.runBuild(BuildSession.java:224)
at org.jetbrains.jps.cmdline.BuildSession.run(BuildSession.java:113)
at org.jetbrains.jps.cmdline.BuildMain$MyMessageHandler$1.run(BuildMain.java:133)
at org.jetbrains.jps.service.impl.SharedThreadPoolImpl$1.run(SharedThreadPoolImpl.java:41)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:744)
Caused by: java.lang.NullPointerException
at java.lang.String.<init>(String.java:200)
at org.jetbrains.asm4.Type.getInternalName(Type.java:560)
at org.jetbrains.jet.codegen.AsmUtil.correctElementType(AsmUtil.java:137)
at org.jetbrains.jet.codegen.intrinsics.ArrayGet.generateImpl(ArrayGet.java:43)
at org.jetbrains.jet.codegen.intrinsics.IntrinsicMethod.generate(IntrinsicMethod.java:40)
at org.jetbrains.jet.codegen.ExpressionCodegen.visitBinaryExpression(ExpressionCodegen.java:2671)
at org.jetbrains.jet.codegen.ExpressionCodegen.visitBinaryExpression(ExpressionCodegen.java:81)
at org.jetbrains.jet.lang.psi.JetBinaryExpression.accept(JetBinaryExpression.java:38)
at org.jetbrains.jet.codegen.ExpressionCodegen.genQualified(ExpressionCodegen.java:235)
... 68 more
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment