You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Annotation attributes not available at runtime #535
Spring has a bunch of use cases for annotations and quite a rich set of convenience classes for introspecting them. They don't seem to fail, much, at runtime in a native image, but they don't actually work either.
Example code:
publicclassAnnotations {
@Autowired(required = false)
publicvoidsetConverters(List<Bar> converters) {
}
publicstaticvoidmain(String[] args) throwsException {
newAnnotations().run();
}
privatevoidrun() throwsException {
Methodmethod = getClass().getMethod("setConverters", List.class);
Autowiredann = method.getAnnotation(Autowired.class);
AnnotationAttributesattributes = AnnotatedElementUtils
.getMergedAnnotationAttributes(method, Autowired.class);
// Null in native image, {required=false} in normal JDKSystem.err.println(attributes);
// Boom! Blows up in native image, {required=false} in normal JDK// System.err.println(AnnotationUtils.getAnnotationAttributes(ann, true));
}
}
I have tried to isolate the failure to specific reflective access to the annotation, but haven't been successful. Once (only) I saw some logs from the call to AnnotatedElementUtils:
Jul 09, 2018 8:51:29 AM org.springframework.core.annotation.AnnotationUtils handleIntrospectionFailure
INFO: Failed to introspect annotations on public void Annotations.setConverters(java.util.List): java.lang.IllegalStateException: Could not obtain annotation attribute value for public abstract boolean org.springframework.beans.factory.annotation.Autowired.required()
The fact that I only saw this once suggests there is perhaps another issue lurking to do with log configuration (Spring uses commons-logging which defaults to java.util.logging if nothing else is available).
I just verified that the following (modified version of the sample application) passes in the spring-core native image tests build against GraalVM 20.0.
Activity
cstancu commentedon Jul 9, 2018
Thank you for reporting! Do you have a repo that we can use to easily replicate this?
dsyer commentedon Jul 9, 2018
The code above will compile and run with just
spring-beans(andspring-corewhich is transitive) on the class path.dsyer commentedon Apr 1, 2019
FWIW I think this is a duplicate of #999.
sbrannen commentedon Mar 15, 2020
I just verified that the following (modified version of the sample application) passes in the
spring-corenative image tests build against GraalVM 20.0.Thus, feel free to close this issue.