bazel: ArrayIndexOutOfBoundsException in turbine with JDK 21 class files

Building with class files emitted by the JDK 21 javac will result in crashes like the following:

java.lang.ArrayIndexOutOfBoundsException: Index -1 out of bounds for length 207
        at com.google.turbine.bytecode.ConstantPoolReader.utf8(ConstantPoolReader.java:120)
        at com.google.turbine.bytecode.ClassReader.readMethodParameters(ClassReader.java:229)
        at com.google.turbine.bytecode.ClassReader.readMethods(ClassReader.java:438)
        at com.google.turbine.bytecode.ClassReader.read(ClassReader.java:105)
        at com.google.turbine.bytecode.ClassReader.read(ClassReader.java:55)
        at com.google.turbine.binder.bytecode.BytecodeBoundClass$1.get(BytecodeBoundClass.java:91)
        at com.google.turbine.binder.bytecode.BytecodeBoundClass$1.get(BytecodeBoundClass.java:88)
        at com.google.common.base.Suppliers$NonSerializableMemoizingSupplier.get(Suppliers.java:183)
        at com.google.turbine.binder.bytecode.BytecodeBoundClass$6.get(BytecodeBoundClass.java:194)
        at com.google.turbine.binder.bytecode.BytecodeBoundClass$6.get(BytecodeBoundClass.java:191)
        at com.google.common.base.Suppliers$NonSerializableMemoizingSupplier.get(Suppliers.java:183)
        at com.google.turbine.binder.bytecode.BytecodeBoundClass$7.get(BytecodeBoundClass.java:207)
        at com.google.turbine.binder.bytecode.BytecodeBoundClass$7.get(BytecodeBoundClass.java:204)
        at com.google.common.base.Suppliers$NonSerializableMemoizingSupplier.get(Suppliers.java:183)
        at com.google.turbine.binder.bytecode.BytecodeBoundClass.typeParameters(BytecodeBoundClass.java:221)
        at com.google.turbine.types.Canonicalize.isRaw(Canonicalize.java:152)
        at com.google.turbine.types.Canonicalize.canon(Canonicalize.java:127)
        at com.google.turbine.types.Canonicalize.canonicalizeClassTy(Canonicalize.java:360)
        at com.google.turbine.types.Canonicalize.canonicalize(Canonicalize.java:115)
        at com.google.turbine.types.Canonicalize.canonicalize(Canonicalize.java:366)
        at com.google.turbine.types.Canonicalize.canonicalizeClassTy(Canonicalize.java:357)
        at com.google.turbine.types.Canonicalize.canonicalizeClassTy(Canonicalize.java:87)
        at com.google.turbine.binder.CanonicalTypeBinder.bind(CanonicalTypeBinder.java:52)
        at com.google.turbine.binder.Binder.canonicalizeTypes(Binder.java:319)
        at com.google.turbine.binder.Binder.bind(Binder.java:172)
        at com.google.turbine.binder.Binder.bind(Binder.java:97)
        at com.google.turbine.main.Main.bind(Main.java:259)
        at com.google.turbine.main.Main.compile(Main.java:157)
        at com.google.turbine.main.Main.compile(Main.java:132)
        at com.google.turbine.main.Main.main(Main.java:88)

The latest JDK 21 builds contain some system classes with MethodParameters attributes that contain empty names. This change was caused by the fix for JDK-8292275: javac does not emit SYNTHETIC and MANDATED flags for parameters by default.

Turbine was fixed to correctly handle these class files in https://github.com/google/turbine/commit/0f203454983d11f842f1b3193799a0f4553228a2, but that change isn’t available in Bazel yet.

I opened https://github.com/bazelbuild/bazel/pulls to update turbine. We should merge that fix and cut a java_rules release that includes the change before JDK 21 is released in September.

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Comments: 16 (12 by maintainers)

Commits related to this issue

Most upvoted comments

Thanks! That’s the solution I’ve taken so far in my in-progress change. MemberName also catches a few other issues which we’ll need to clean up, but am going to hold off until I can re-enable it.

Hm, it looks like updating to a newer version of rules_java toolchains fixes this. We run into https://github.com/google/error-prone/pull/3976 but avoid this issue.

@bazel-io fork 6.3.0