Skip to content

Build time initialization of org.springframework.util.unit.DataSize #4489

@mhalbritter

Description

@mhalbritter

Hey,

I'm struggling to understand build time initialization. I don't get why the build time initialization of org.springframework.util.unit.DataSize is necessary in our spring-boot native image.

The native image building fails if we don't include --initialize-at-build-time=org.springframework.util.unit.DataSize.

I wasn't able to build a minimal reproducer for this. Here's the full reproducer:

git clone --depth=1 --branch mh/data-size https://github.com/mhalbritter/spring-framework.git
cd spring-framework
./gradlew publishToMavenLocal -xtest -xjavadoc -xdokkaHtmlPartial

git clone --depth=1 --branch aot https://github.com/spring-projects/spring-boot.git
cd spring-boot
./gradlew publishToMavenLocal -xtest -xaggregatedJavadoc -xasciidoctor -xasciidoctorPdf -xzip

git clone https://github.com/snicoll-scratches/demo-native-sample.git
cd demo-native-sample
./mvnw package -Pnative

When running this, i get the error

Caused by: com.oracle.graal.pointsto.constraints.UnsupportedFeatureException: No instances of org.springframework.util.unit.DataSize are allowed in the image heap as this class should be initialized at image runtime. To see how this object got instantiated use --trace-object-instantiation=org.springframework.util.unit.DataSize.

When adding the --trace-object-initialization=... from the error message, I get:

Caused by: com.oracle.graal.pointsto.constraints.UnsupportedFeatureException: No instances of org.springframework.util.unit.DataSize are allowed in the image heap as this class should be initialized at image runtime. Object has been initialized without the native-image initialization instrumentation and the stack trace can't be tracked.

Adding --initialize-at-build-time=org.springframework.util.unit.DataSize works, but why is this necessary?

The only thing which we initialize at build time (via native-image.properties file in spring-core.jar) is org.springframework.core.NativeDetector.

I used the latest available 22.1-dev build (https://github.com/graalvm/graalvm-ce-dev-builds/releases/tag/22.1.0-dev-20220411_0809)

openjdk version "17.0.3" 2022-04-19
OpenJDK Runtime Environment GraalVM CE 22.1.0-dev (build 17.0.3+5-jvmci-22.1-b04)
OpenJDK 64-Bit Server VM GraalVM CE 22.1.0-dev (build 17.0.3+5-jvmci-22.1-b04, mixed mode, sharing)

OS is Linux aarch64.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions