Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build time initialization of org.springframework.http.HttpStatus #4673

Closed
sdeleuze opened this issue Jun 27, 2022 · 5 comments
Closed

Build time initialization of org.springframework.http.HttpStatus #4673

sdeleuze opened this issue Jun 27, 2022 · 5 comments
Assignees
Labels
bug native-image spring spring related issue
Milestone

Comments

@sdeleuze
Copy link
Collaborator

sdeleuze commented Jun 27, 2022

Since the introduction of Spring mechanism to make some fields constant at build time without having to use class build-time initialization (see this commit), org.springframework.http.HttpStatus (sources) is one of the few remaining Spring Framework class that requires build time initialization.

I suspect this is a GraalVM bug that could be fixed like done for DataSize. I suspect it is caused by this line that is not detected as safe by GraalVM so it requires manual build-time init which is unfortunate and something we would like to avoid.

Could you please check if that's fixable on your side (warning : for now, I will bring back a META-INF/native-image/org.springframework/spring-web/native-image.properties with Args = --initialize-at-build-time=org.springframework.http.HttpStatus so make sure to remove it to reproduce. Maybe just copy HttpStatus.java source code since it is pretty isolated.

Please tag this issue with the spring label.

Please find the stacktrace below:

Error: Classes that should be initialized at run time got initialized during image building:
 org.springframework.http.HttpStatus was unintentionally initialized at build time. org.springframework.http.HttpStatus caused initialization of this class with the following trace: 
	at org.springframework.http.HttpStatus.<clinit>(HttpStatus.java:42)
	at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Unknown Source)
	at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
	at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:568)
	at java.lang.Class.getEnumConstantsShared(Class.java:3837)
	at java.lang.Class.enumConstantDirectory(Class.java:3859)
	at java.lang.Enum.valueOf(Enum.java:267)
	at sun.reflect.annotation.AnnotationParser.parseEnumValue(AnnotationParser.java:479)
	at sun.reflect.annotation.AnnotationParser.parseMemberValue(AnnotationParser.java:344)
	at java.lang.reflect.Method.getDefaultValue(Method.java:717)
	at com.oracle.svm.reflect.hosted.ReflectionDataBuilder.registerTypesForMethod(ReflectionDataBuilder.java:506)
	at com.oracle.svm.reflect.hosted.ReflectionDataBuilder.processMethodMetadata(ReflectionDataBuilder.java:284)
	at com.oracle.svm.reflect.hosted.ReflectionDataBuilder.duringAnalysis(ReflectionDataBuilder.java:185)
	at com.oracle.svm.reflect.hosted.ReflectionFeature.duringAnalysis(ReflectionFeature.java:189)
	at com.oracle.svm.hosted.NativeImageGenerator.lambda$runPointsToAnalysis$10(NativeImageGenerator.java:726)
	at com.oracle.svm.hosted.NativeImageGenerator$$Lambda$1405/0x00000007c0fccea0.accept(Unknown Source)
------------------------------------------------------------------------------------------------------------------------
	at com.oracle.svm.hosted.FeatureHandler.forEachFeature(FeatureHandler.java:74)
	at com.oracle.svm.hosted.NativeImageGenerator.lambda$runPointsToAnalysis$11(NativeImageGenerator.java:726)
	at com.oracle.svm.hosted.NativeImageGenerator$$Lambda$552/0x00000007c1716428.apply(Unknown Source)
	at com.oracle.graal.pointsto.PointsToAnalysis.runAnalysis(PointsToAnalysis.java:751)
	at com.oracle.svm.hosted.NativeImageGenerator.runPointsToAnalysis(NativeImageGenerator.java:723)
	at com.oracle.svm.hosted.NativeImageGenerator.doRun(NativeImageGenerator.java:558)
	at com.oracle.svm.hosted.NativeImageGenerator.run(NativeImageGenerator.java:515)
	at com.oracle.svm.hosted.NativeImageGeneratorRunner.buildImage(NativeImageGeneratorRunner.java:407)
	at com.oracle.svm.hosted.NativeImageGeneratorRunner.build(NativeImageGeneratorRunner.java:585)
	at com.oracle.svm.hosted.NativeImageGeneratorRunner.main(NativeImageGeneratorRunner.java:128)
	at com.oracle.svm.hosted.NativeImageGeneratorRunner$JDK9Plus.main(NativeImageGeneratorRunner.java:615)
@sdeleuze sdeleuze changed the title Build time initialization of org.springframework.http.HttpStatus Build time initialization of org.springframework.http.HttpStatus Jun 27, 2022
sdeleuze added a commit to sdeleuze/spring-framework that referenced this issue Jun 27, 2022
As spring-projectsgh-28624 supports only static boolean fields, we still
need a few classes to be initialized at build time.

Such explicit configuration should be in theory avoidable,
so we will work with the GraalVM team to see if this can be
fixed, see for example
oracle/graal#4673
for HttpStatus.

See spring-projectsgh-28683
sdeleuze added a commit to sdeleuze/spring-framework that referenced this issue Jun 27, 2022
As spring-projectsgh-28624 supports only static boolean fields, we still
need a few classes to be initialized at build time.

Such explicit configuration should be in theory avoidable,
so we will work with the GraalVM team to see if this can be
fixed, see for example
oracle/graal#4673
for HttpStatus.

See spring-projectsgh-28624
@fniephaus fniephaus added the spring spring related issue label Jun 28, 2022
@sdeleuze
Copy link
Collaborator Author

If that can help, the related JAR can be found in https://search.maven.org/artifact/org.springframework/spring-web.

@oubidar-Abderrahim oubidar-Abderrahim self-assigned this Jul 18, 2022
@oubidar-Abderrahim
Copy link
Member

Thank you for reporting this, We will take a look into this and get back to you if needed.

@christianwimmer
Copy link
Member

@sdeleuze can you please check if the problem is still reproducible (with the latest daily build of GraalVM, as well as with GraalVM 22.2).

The call to Method.getDefaultValue from ReflectionDataBuilder.registerTypesForMethod was removed as part of the re-work of how we handle annotations in GraalVM 22.2. So at least the failing stack trace is no longer possible

@sdeleuze
Copy link
Collaborator Author

I confirm it works out of the box with GraalVM 22.2 and latest dev build without any --initialize-at-build-time configuration so you close this issue. Please set the milestone to 22.2.

@christianwimmer
Copy link
Member

Thanks for confirming that it works now!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug native-image spring spring related issue
Projects
Native Image
  
To do
Development

No branches or pull requests

4 participants