Skip to content

Commit c205a89

Browse files
authored
ClassfileParser: allow missing param names (for JDK 21) (#17536)
this is a forward port of scala/scala#10397 (fixing scala/bug#12783, from which Scala 3 also suffers) — the same fix we'll be shipping in 2.12.18 and 2.13.11 I haven't included a unit test, because * a similar change has already been well validated in a Scala 2 context * without this change, the compiler can't compile anything at all on JDK 21 * we need the reference compiler to include this change before we can bootstrap on JDK 21 anyway but I did manually test it locally, by bootstrapping on JDK 11, publishing the resulting compiler locally, and then launching the REPL and evaluating `2 + 2` on 3.3.0-RC6, that fails with: > error while loading AccessFlag, > class file /modules/java.base/java/lang/reflect/AccessFlag.class is broken, reading aborted with class java.lang.RuntimeException > bad constant pool index: 0 at pos: 5189 > error while loading ElementType, > class file /modules/java.base/java/lang/annotation/ElementType.class is broken, reading aborted with class java.lang.RuntimeException > bad constant pool index: 0 at pos: 1220 > 2 errors found whereas with this change, it succeeds.
2 parents 3d1b6a4 + 5038c9c commit c205a89

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

compiler/src/dotty/tools/dotc/core/classfile/ClassfileParser.scala

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -758,10 +758,12 @@ class ClassfileParser(
758758
case tpnme.MethodParametersATTR =>
759759
val paramCount = in.nextByte
760760
for i <- 0 until paramCount do
761-
val name = pool.getName(in.nextChar)
761+
val index = in.nextChar
762762
val flags = in.nextChar
763-
if (flags & JAVA_ACC_SYNTHETIC) == 0 then
764-
res.namedParams += (i -> name.name)
763+
if index != 0 then
764+
val name = pool.getName(index)
765+
if (flags & JAVA_ACC_SYNTHETIC) == 0 then
766+
res.namedParams += (i -> name.name)
765767

766768
case tpnme.AnnotationDefaultATTR =>
767769
sym.addAnnotation(Annotation(defn.AnnotationDefaultAnnot, Nil, sym.span))

0 commit comments

Comments
 (0)