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

Record beans do not compile to native images #30383

Closed
sdeleuze opened this issue Apr 26, 2023 · 5 comments
Closed

Record beans do not compile to native images #30383

sdeleuze opened this issue Apr 26, 2023 · 5 comments
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) theme: aot An issue related to Ahead-of-time processing type: regression A bug that is also a regression
Milestone

Comments

@sdeleuze
Copy link
Contributor

sdeleuze commented Apr 26, 2023

After this change related to #29246 in Spring Framework 6.0.8, "queryAllDeclaredMethods": true is added on all registered beans (for good purpose).

I think this change has uncovered the fact that Boot is not adding invocation hints for record components on @ConfigurationProperties (like ReflectionForBindingRegistrar does on Framework side). Before Spring Framework 6.0.7, records components were, I guess, invisible so no error. With Spring Framework 6.0.8+, "queryAllDeclaredMethods": true make those records components visible.

That means with Boot 3.0.6, with:

@ConfigurationProperties("sample")
record SampleConfigurationProperties(String message) { }

I get the following error:

Fatal error: com.oracle.svm.core.util.VMError$HostedError: com.oracle.svm.core.util.VMError$HostedError: New Method or Constructor found as reachable after static analysis: public java.lang.String com.example.SampleConfigurationProperties.message()

Can be reproduced with https://github.com/sdeleuze/demo-profile-aot when updating to Boot 3.0.6.

To avoid such error and properly support record component binding in @ConfigurationProperties, I think invocation hints should be added to record components for such class.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Apr 26, 2023
@wilkinsona wilkinsona changed the title Add reflection hints for record components for @ConfigurationProperties Configuration property binding to a record fails in a native image Apr 26, 2023
@wilkinsona wilkinsona added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Apr 26, 2023
@wilkinsona
Copy link
Member

wilkinsona commented Apr 26, 2023

It looks like the configuration properties smoke test started failing with a similar error on 19 April:

Fatal error: com.oracle.svm.core.util.VMError$HostedError: com.oracle.svm.core.util.VMError$HostedError: New Method or Constructor found as reachable after static analysis: public com.example.configprops.records.NestedNotInner com.example.configprops.records.AppPropertiesRecord.nestedNotInner()	
	at org.graalvm.nativeimage.builder/com.oracle.svm.core.util.VMError.shouldNotReachHere(VMError.java:72)	
	at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGenerator.doRun(NativeImageGenerator.java:696)	
	at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGenerator.run(NativeImageGenerator.java:535)	
	at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGeneratorRunner.buildImage(NativeImageGeneratorRunner.java:403)	
	at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGeneratorRunner.build(NativeImageGeneratorRunner.java:580)	
	at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGeneratorRunner.main(NativeImageGeneratorRunner.java:128)	
Caused by: com.oracle.svm.core.util.VMError$HostedError: New Method or Constructor found as reachable after static analysis: public com.example.configprops.records.NestedNotInner com.example.configprops.records.AppPropertiesRecord.nestedNotInner()	
	at org.graalvm.nativeimage.builder/com.oracle.svm.core.util.VMError.shouldNotReachHere(VMError.java:68)	
	at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.reflect.ReflectionFeature.getOrCreateAccessor(ReflectionFeature.java:121)	
	at org.graalvm.nativeimage.builder/com.oracle.svm.core.reflect.target.ExecutableAccessorComputer.transform(ExecutableAccessorComputer.java:43)	
	at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.substitute.ComputedValueField.computeValue(ComputedValueField.java:343)	
	at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.substitute.ComputedValueField.readValue(ComputedValueField.java:313)	
	at org.graalvm.nativeimage.builder/com.oracle.svm.core.meta.ReadableJavaField.readFieldValue(ReadableJavaField.java:38)	
	at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.ameta.AnalysisConstantReflectionProvider.readValue(AnalysisConstantReflectionProvider.java:97)	
	at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.meta.HostedField.readValue(HostedField.java:161)	
	at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.image.NativeImageHeap.addObjectToImageHeap(NativeImageHeap.java:439)	
	at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.image.NativeImageHeap.addObject(NativeImageHeap.java:295)	
	at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.image.NativeImageHeap.processAddObjectWorklist(NativeImageHeap.java:598)	
	at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.image.NativeImageHeap.addTrailingObjects(NativeImageHeap.java:198)	
	at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGenerator.doRun(NativeImageGenerator.java:678)	
	... 4 more

That was when the smoke tests were updated to test Boot 3.0.6 snapshots. This fits with the Framework changes being related as moving to Boot 3.0.6 snapshots meant we also upgraded to Framework 6.0.8.

@wilkinsona wilkinsona added type: regression A bug that is also a regression and removed type: bug A general bug labels Apr 26, 2023
@bclozel bclozel transferred this issue from spring-projects/spring-boot Apr 26, 2023
@bclozel bclozel added type: bug A general bug in: core Issues in core modules (aop, beans, core, context, expression) theme: aot An issue related to Ahead-of-time processing and removed type: regression A bug that is also a regression labels Apr 26, 2023
@bclozel bclozel added this to the 6.0.9 milestone Apr 26, 2023
@sdeleuze sdeleuze changed the title Configuration property binding to a record fails in a native image Record beans do not compile to native images Apr 27, 2023
@sdeleuze sdeleuze added type: regression A bug that is also a regression and removed type: bug A general bug labels Apr 27, 2023
sdeleuze added a commit that referenced this issue Apr 28, 2023
After b374824 related
to gh-29246, `"queryAllDeclaredMethods": true` is now added
on all registered beans.

This legit change triggers oracle/graal#6510. This
commit workarounds this GraalVM bug, and should be
removed once the GraalVM fix has reached a wide enough
audience.

Closes gh-30383
@snicoll
Copy link
Member

snicoll commented Apr 28, 2023

This commit workarounds this GraalVM bug, and should be removed once the GraalVM fix has reached a wide enough audience.

Please create a task to remove the code or we will probably forget about it. Thanks!

@AdrienBennadji
Copy link

Hi, not sure if I should open a new issue of reopen this one but migrating my application to spring-boot 3.2.0 seems to break records again.

Caused by: com.oracle.svm.core.util.VMError$HostedError: New Method or Constructor found as reachable after static analysis: public <redacted>.AppProperties$Secured <redacted>.AppProperties.secured()

Here AppProperties and Secured are both records, and I use @NestedConfigurationProperty.
Changing from records to classes make the compilation work.

@sbrannen
Copy link
Member

@AdrienBennadji, since this issue was closed 8 months ago, please open a new issue.

And in that issue, please include a small example that reproduces the problem -- preferably a simple application or test class that we can run ourselves (either attached to the issue as a ZIP file or as a public Git repository).

Thanks

@AdrienBennadji
Copy link

@sbrannen Thank you for your response. I upgraded the version of the Graalvm image i use to build my applications and it fixed the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) theme: aot An issue related to Ahead-of-time processing type: regression A bug that is also a regression
Projects
None yet
Development

No branches or pull requests

7 participants