-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Closed
Labels
Description
Describe the issue
Native images unable to access declared annotations of Java records through java.lang.reflect.RecordComponent.declaredAnnotations
.
A simple application like the following cannot compile into a native image:
import java.lang.annotation.Annotation;
import java.lang.reflect.RecordComponent;
public class Main {
public static void main(String[] args) {
RecordComponent[] recordComponents = F.class.getRecordComponents();
for (RecordComponent component: recordComponents) {
System.out.println(component);
Annotation[] annotations = component.getAnnotations();
for (Annotation annotation : annotations) {
System.out.println(annotation);
}
}
F x = new F("x");
System.out.println(x);
}
static record F(String name) {
}
}
Steps to reproduce the issue
Please include both build steps as well as run steps
cd /tmp
git clone --branch record-annotations-21.3 https://github.com/zakkak/issue-reproducers reproducers
cd reproducers
mvn package
export JAVA_HOME=/opt/jvms/graalvm-ce-java17-21.3.0
$JAVA_HOME/bin/native-image --initialize-at-build-time --diagnostics-mode \
--no-fallback -H:+ReportExceptionStackTraces \
-H:ReflectionConfigurationFiles=./META-INF/native-image/reflect-config.json \
-jar target/reproducer-1.0-SNAPSHOT.jar
./reproducer-1.0-SNAPSHOT
Describe GraalVM and your environment:
- GraalVM version: CE 21.3.0
- JDK major version: 17
- OS: Fedora 34
- Architecture: AMD64
More details
The build fails with:
Error: com.oracle.svm.hosted.substitute.DeletedElementException: Unsupported method java.lang.Class.getConstantPool() is reachable: The declaring class of this element has been substituted, but this element is not present in the substitution class
To diagnose the issue, you can add the option --report-unsupported-elements-at-runtime. The unsupported element is then reported at run time when it is accessed the first time.
Detailed message:
Trace:
at parsing java.lang.System$2.getConstantPool(System.java:2262)
Call path from entry point to java.lang.System$2.getConstantPool(Class):
at java.lang.System$2.getConstantPool(System.java:2262)
at java.lang.reflect.RecordComponent.declaredAnnotations(RecordComponent.java:198)
at java.lang.reflect.RecordComponent.getDeclaredAnnotations(RecordComponent.java:224)
at java.lang.reflect.RecordComponent.getAnnotations(RecordComponent.java:215)
at com.oracle.svm.core.JavaMainWrapper.runCore(JavaMainWrapper.java:147)
at com.oracle.svm.core.JavaMainWrapper.run(JavaMainWrapper.java:183)
...
antonygunawan94, Chexpir, geoand, sureshg, luneo7 and 2 more