Skip to content

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

@sdeleuze

Description

@sdeleuze

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?

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions