Skip to content

File option type doesn't work in native #960

Closed
@wirthi

Description

@wirthi

Hi,

tl;dr: I believe you are missing native reflection configuration for at least ch.qos.logback.classic.joran.SerializedModelConfigurator for a Spring Shell app to properly work with the native compile feature.

I have used Spring Initializr to create a Spring Boot 3.2.0 app and included Spring Shell as (only) dependency. Java 21, Maven.

demo.zip
demoWithNativeBuildTools.zip (edit: have added this file that includes the proper config in pom.xml)

When the native compile feature is used (GraalVM) on the generated application (without modifications, except adding native-build-tools configuration), an executable is successfully generated. That executable starts, but fails with a NullPointerException (in the constructor of FileInputStream) on e.g. this command:

shell --file AValidFileName

The NPE is not of relevance, it is a consequence of the actual problem: there is incomplete configuration for the reflection at runtime. Using the -H:ThrowMissingRegistrationErrors=true option of GraalVM native-image (23.1 or later) I see the following problem (note: this is print when executing the generated image):
Exception in thread "main" org.graalvm.nativeimage.MissingReflectionRegistrationError: The program tried to reflectively access class ch.qos.logback.classic.joran.SerializedModelConfigurator without it being registered for runtime reflection. Add ch.qos.logback.classic.joran.SerializedModelConfigurator to the reflection metadata to solve this problem. See https://www.graalvm.org/latest/reference-manual/native-image/metadata/#reflection for help.
This message typically means that this dependency is using reflection, but you don't provide reflection configuration, so native-image generates an image that can only fail when this codepath is taken - it throws the NullPointerException.

Note:

  • I did add the native-build-tools plugin and metadataRepository config as described in your documentation. This is NOT in the attached file however.
  • ./mvnw package -Pnative as listed in the documentation does not trigger a native compile for me. I am using ./mvnw -Pnative native:compile instead.

(discussed in https://graalvm.slack.com/archives/GPEQFN084/p1703162180614929)

Thanks,
Christian Wirth
GraalVM Native Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions