Skip to content

Conversation

@academey
Copy link
Owner

Summary

  • Fixes native compilation failure when using Java 22 with GraalVM
  • Adds proper RuntimeHints for SLF4J service providers
  • Ensures compatibility with both Java 21 and Java 22

Details

This PR resolves issue spring-projects#494 where native compilation fails under Java 22 but works on Java 21. The root cause was that SLF4J service providers (NOP_FallbackServiceProvider and SubstituteServiceProvider) were being initialized at runtime instead of build time in GraalVM native images.

Changes made:

  1. Updated SpringAiCoreRuntimeHints.java to register SLF4J classes for reflection and build-time initialization
  2. Added comprehensive tests in SpringAiCoreRuntimeHintsTests.java

Error fixed:

Error: An object of type 'org.slf4j.helpers.NOP_FallbackServiceProvider' was found in the image heap... Error: An object of type 'org.slf4j.helpers.SubstituteServiceProvider' was found in the image heap... 

Test Plan

  • Added unit tests for all registered types
  • Verified SLF4J types are properly registered
  • Test native compilation with Java 21
  • Test native compilation with Java 22
  • Ensure no regression in regular JVM mode

Fixes spring-projects#494

@academey academey force-pushed the fix/issue-494-native-java22 branch 3 times, most recently from 1e06a4b to cc9d20c Compare July 18, 2025 02:31
academey added 2 commits July 18, 2025 17:26
This commit resolves the native compilation failure when using Java 22 with GraalVM. The issue was caused by SLF4J service providers being initialized at runtime instead of build time. Changes: - Add SLF4J RuntimeHints to SpringAiCoreRuntimeHints for native compilation - Register NOP_FallbackServiceProvider and SubstituteServiceProvider for build-time initialization - Add comprehensive tests for all registered types including SLF4J This fix ensures compatibility with both Java 21 and Java 22 for native image compilation. Fixes spring-projects#494 Signed-off-by: academey <academey@gmail.com>
- Update copyright year from 2023-2024 to 2023-2025 - Remove @author Christian Tzolov as per contributor guidelines Signed-off-by: academey <academey@gmail.com>
@academey academey force-pushed the fix/issue-494-native-java22 branch from cc9d20c to e2b2870 Compare July 18, 2025 08:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants