Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8342699

java.lang.classfile.CodeModel.elementList() throws unspecified java.lang.IllegalArgumentException

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • 24
    • None
    • core-libs

      When using the ClassFile, for certain contents of a class file, a call to CodeModel.elementList() throws an unspecified java.lang.IllegalArgumentException.

      The sample code looks as follows:

          ClassFile cf = ClassFile.of(...);
          ClassModel model = cf.parse(...);
          for (final MethodModel method : model.methods()) {
              final Optional<CodeModel> methodCode = method.code();
              if (methodCode.isEmpty()) {
                  continue;
              }
              for (final CodeElement codeElement : methodCode.get().elementList()) {
                  ...
          ...

      This results in:

      java.lang.IllegalArgumentException: Bytecode offset out of range; bci=26, codeLength=9
          at java.base/jdk.internal.classfile.impl.CodeImpl.getLabel(CodeImpl.java:101)
          at java.base/jdk.internal.classfile.impl.AnnotationReader.getLabel(AnnotationReader.java:174)
          at java.base/jdk.internal.classfile.impl.AnnotationReader.readLocalVarEntries(AnnotationReader.java:253)
          at java.base/jdk.internal.classfile.impl.AnnotationReader.readTypeAnnotation(AnnotationReader.java:201)
          at java.base/jdk.internal.classfile.impl.AnnotationReader.readTypeAnnotations(AnnotationReader.java:93)
          at java.base/jdk.internal.classfile.impl.BoundAttribute$BoundRuntimeVisibleTypeAnnotationsAttribute.annotations(BoundAttribute.java:833)
          at java.base/java.util.Optional.ifPresent(Optional.java:178)
          at java.base/jdk.internal.classfile.impl.CodeImpl.inflateTypeAnnotations(CodeImpl.java:332)
          at java.base/jdk.internal.classfile.impl.CodeImpl.inflateMetadata(CodeImpl.java:127)
          at java.base/jdk.internal.classfile.impl.CodeImpl.forEach(CodeImpl.java:166)
          at java.base/java.lang.classfile.CompoundElement.elementList(CompoundElement.java:89)
          ...

      This was reproduced against JDK mainline (Java 24). The same is also reproduced in Java 23, although, the method elementList() doesn't exist in Java 23 and instead the call to CodeModel.elements() throws this same unspecified exception.

            liach Chen Liang
            jpai Jaikiran Pai
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: