bug
bug copied to clipboard
NoSuchElementException in ClassFileParser for Java inner classes referring to outer parameters
% tail test/files/run/som/*.{java,scala}
==> test/files/run/som/Java_1.java <==
public class Java_1<K, V> {
public class Inner extends Java_1<K, V> {
}
}
class SomeOtherJava {
}
==> test/files/run/som/Macros_1.scala <==
def fImpl(c: Context): c.Tree = {
import c.universe._
import reflect.runtime.{universe => ru}
val formatterSym = c.universe.symbolOf[bakery.SomeOtherJava]
ru.internal.createImporter(c.universe).importSymbol(formatterSym)
q"()"
}
}
==> test/files/run/som/Test_2.scala <==
object Test {
bakery.Bakery.f
}
% javac -d /tmp test/files/run/som/*.java && qscalac -classpath /tmp -d /tmp test/files/run/som/Macros_1.scala && qscalac -classpath /tmp -d /tmp test/files/run/som/Test_2.scala
error: error while loading Java_1$Inner, class file '/tmp/bakery/Java_1$Inner.class' is broken
(class java.util.NoSuchElementException/key not found: K)
one error found
% tail sandbox/{Java_1.java,test.scala}
==> sandbox/Java_1.java <==
public class Java_1<K, V> {
public class Inner extends Java_1<K, V> {
}
}
==> sandbox/test.scala <==
object Test {
classOf[Java_1$Inner]
}
% javac -d /tmp sandbox/Java_1.java && qscalac -classpath /tmp sandbox/test.scala
error: error while loading Java_1$Inner, class file '/tmp/Java_1$Inner.class' is broken
(class java.util.NoSuchElementException/key not found: K)
sandbox/test.scala:2: warning: a pure expression does nothing in statement position; you may be omitting necessary parentheses
classOf[Java_1$Inner]
^
one warning found
one error found
As reported and discussed https://groups.google.com/d/msg/scala-internals/p3LUQSniAl8/2GB1ok9SK2MJ
Imported From: https://issues.scala-lang.org/browse/SI-9152?orig=1 Reporter: @retronym Affected Versions: 2.11.5
remains reproducible on 2.12.4
perhaps a .hasCompleteInfo check is missing somewhere? I hit this error in a closed-source compiler plugin, in reference to Hashtable.Entry in the Java stdlib. Adding such a check (as suggested by @adriaanm) fixed it.
I hit this in metals in the context of https://github.com/scala/scala-dev/issues/905.
package p;
class C<X> {
class I extends C<X> { }
}
Then in the Scala REPL
scala> :power
scala> rootMirror.getClassIfDefined("p.C$I").info
error: error while loading C$I, class file ./p/C$I.class is broken
(class java.util.NoSuchElementException/key not found: X)
java.util.NoSuchElementException: key not found: X
at scala.collection.immutable.Map$EmptyMap$.apply(Map.scala:243)
at scala.collection.immutable.Map$EmptyMap$.apply(Map.scala:239)
at scala.tools.nsc.symtab.classfile.ClassfileParser.sig2type$1(ClassfileParser.scala:752)
at scala.tools.nsc.symtab.classfile.ClassfileParser.processClassType$1(ClassfileParser.scala:686)
at scala.tools.nsc.symtab.classfile.ClassfileParser.sig2type$1(ClassfileParser.scala:711)
at scala.tools.nsc.symtab.classfile.ClassfileParser.scala$tools$nsc$symtab$classfile$ClassfileParser$$sigToType(ClassfileParser.scala:797)
at scala.tools.nsc.symtab.classfile.ClassfileParser$ClassTypeCompleter.complete(ClassfileParser.scala:1298)
at scala.reflect.internal.Symbols$Symbol.completeInfo(Symbols.scala:1584)
at scala.reflect.internal.Symbols$Symbol.info(Symbols.scala:1549)