-
Bug
-
Resolution: Duplicate
-
P4
-
None
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.
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.
- duplicates
-
JDK-8342465 Improve API documentation for java.lang.classfile
-
- Resolved
-
- relates to
-
JDK-8342465 Improve API documentation for java.lang.classfile
-
- Resolved
-