Skip to content

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

Closed
@sdeleuze

Description

@sdeleuze

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)

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions