-
Bug
-
Resolution: Duplicate
-
P4
-
None
Consider this very trivial code:
import java.lang.classfile.ClassFile;
import java.lang.classfile.ClassModel;
import java.lang.classfile.MethodModel;
import java.nio.file.Path;
public class ClassFileTest {
public static void main(String[] args) throws Exception {
final Path classFile = Path.of(args[0]); // path to a class file
final ClassModel model = ClassFile.of().parse(classFile);
for (MethodModel method : model.methods()) {
method.parent().ifPresent((p) -> {
p.thisClass().asSymbol();
});
}
System.out.println("Successfully completed parsing methods of "
+ model.thisClass().asInternalName());
}
}
The code use java.lang.classfile.ClassFile instance to parse a class file content. The returned ClassModel is then traversed for the methods and for each method the code checks the presence of a parent and when it finds the parent, the code then calls the `asSymbol()` method on the `ClassEntry` representing the parent. For some classes the `ClassEntry.asSymbol()` call results in an unspecified java.lang.IllegalArgumentException which looks like:
Exception in thread "main" java.lang.IllegalArgumentException: not a valid reference type descriptor: Lfoo/bar/hello//org/myapp/hello/FooBar;
at java.base/jdk.internal.constant.ReferenceClassDescImpl.of(ReferenceClassDescImpl.java:59)
at java.base/java.lang.constant.ClassDesc.ofDescriptor(ClassDesc.java:171)
at java.base/java.lang.constant.ClassDesc.ofInternalName(ClassDesc.java:113)
at java.base/jdk.internal.classfile.impl.AbstractPoolEntry$ClassEntryImpl.asSymbol(AbstractPoolEntry.java:544)
at ClassFileTest.lambda$main$0(ClassFileTest.java:12)
at java.base/java.util.Optional.ifPresent(Optional.java:178)
at ClassFileTest.main(ClassFileTest.java:11)
FWIW, from the command line "javap -c -v -p" against that same class file works fine without any errors.
The issue reproduces both on JDK 23 as well as latest JDK mainline (JDK 24).
import java.lang.classfile.ClassFile;
import java.lang.classfile.ClassModel;
import java.lang.classfile.MethodModel;
import java.nio.file.Path;
public class ClassFileTest {
public static void main(String[] args) throws Exception {
final Path classFile = Path.of(args[0]); // path to a class file
final ClassModel model = ClassFile.of().parse(classFile);
for (MethodModel method : model.methods()) {
method.parent().ifPresent((p) -> {
p.thisClass().asSymbol();
});
}
System.out.println("Successfully completed parsing methods of "
+ model.thisClass().asInternalName());
}
}
The code use java.lang.classfile.ClassFile instance to parse a class file content. The returned ClassModel is then traversed for the methods and for each method the code checks the presence of a parent and when it finds the parent, the code then calls the `asSymbol()` method on the `ClassEntry` representing the parent. For some classes the `ClassEntry.asSymbol()` call results in an unspecified java.lang.IllegalArgumentException which looks like:
Exception in thread "main" java.lang.IllegalArgumentException: not a valid reference type descriptor: Lfoo/bar/hello//org/myapp/hello/FooBar;
at java.base/jdk.internal.constant.ReferenceClassDescImpl.of(ReferenceClassDescImpl.java:59)
at java.base/java.lang.constant.ClassDesc.ofDescriptor(ClassDesc.java:171)
at java.base/java.lang.constant.ClassDesc.ofInternalName(ClassDesc.java:113)
at java.base/jdk.internal.classfile.impl.AbstractPoolEntry$ClassEntryImpl.asSymbol(AbstractPoolEntry.java:544)
at ClassFileTest.lambda$main$0(ClassFileTest.java:12)
at java.base/java.util.Optional.ifPresent(Optional.java:178)
at ClassFileTest.main(ClassFileTest.java:11)
FWIW, from the command line "javap -c -v -p" against that same class file works fine without any errors.
The issue reproduces both on JDK 23 as well as latest JDK mainline (JDK 24).
- duplicates
-
JDK-8342468 Improve API documentation for java.lang.classfile.constantpool
- Resolved