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

Native compilation broken by adding "queryAllDeclaredMethods": true to Java records #6510

Closed
sdeleuze opened this issue Apr 27, 2023 · 2 comments
Assignees
Labels
bug native-image spring spring related issue

Comments

@sdeleuze
Copy link
Collaborator

It looks like we have uncovered a potential GraalVM bug that breaks Spring Boot 3.0.6+ application using Spring beans that are records, which is a pretty propular use cases with @ConfigurationProperties. The related Spring Framework issue is spring-projects/spring-framework#30383, and it looks like a record specific follow-up of #5139 cc @cstancu @loicottet.

This regression has been cause by an IMO legit Spring Framework refinement that adds "queryAllDeclaredMethods": true on all beans for 2 reasons:

  • It is by design required if we want properly to support init/destroy methods
  • It will improve the compatiblity with upcoming GraalVM reflection support changes

So this works:

{
    "name": "com.example.SampleConfigurationProperties",
    "methods": [
      {
        "name": "<init>",
        "parameterTypes": [
          "java.lang.String"
        ]
      }
    ]
  }

And this fails:

{
    "name": "com.example.SampleConfigurationProperties",
    "queryAllDeclaredMethods": true,
    "methods": [
      {
        "name": "<init>",
        "parameterTypes": [
          "java.lang.String"
        ]
      }
    ]
  }

With 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.

As part of spring-projects/spring-framework#30383 and since this is a blocking issue, we will likely workaround by adding invocation metadata which works:

{
    "name": "com.example.SampleConfigurationProperties",
    "queryAllDeclaredMethods": true,
    "allDeclaredMethods": true,
    "methods": [
      {
        "name": "<init>",
        "parameterTypes": [
          "java.lang.String"
        ]
      }
    ]
  }

Could you please fix this and backport it to GraalVM 22.3.x maintenance release?

@christianwimmer
Copy link

I'll have a look at the problem

@christianwimmer
Copy link

The bug is already fixed by #5643 in master and the upcoming 23.0 release. I will make sure the fix gets backported to the next 22.3 update release.

sdeleuze added a commit to spring-projects/spring-framework 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
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
None yet
Development

No branches or pull requests

3 participants