Skip to content

fix: initialize Minestom LoginListener at run time for native image#910

Merged
mworzala merged 1 commit into
mainfrom
fix/native-image-loginlistener-securerandom
Jun 14, 2026
Merged

fix: initialize Minestom LoginListener at run time for native image#910
mworzala merged 1 commit into
mainfrom
fix/native-image-loginlistener-securerandom

Conversation

@mworzala

Copy link
Copy Markdown
Contributor

Problem

The map-isolate native image build fails during analysis:

Detected an instance of Random/SplittableRandom class in the image heap.
  scanning root java.security.SecureRandom@...: NativePRNG embedded in
    net.minestom.server.listener.preplay.LoginListener.loginStartListener(LoginListener.java:79)

Minestom's LoginListener holds a static SecureRandom. HCNativeImageFeature blanket-initializes every net.minestom.* package at build time, so that field is constructed during image generation and lands in the image heap — which GraalVM forbids for Random/SecureRandom (cached seed values). This surfaced after the recent Minestom update.

A --initialize-at-build-time=java.security.SecureRandom flag does not help — GraalVM's DisallowedImageHeapObjects check rejects such instances regardless of init policy. The instance simply must not be created at build time.

Fix

Initialize LoginListener at run time so its SecureRandom is never constructed during image generation. This follows the existing precedent in the same file (PlayerSocketConnection, NetworkBufferImpl, etc. are already runtime-init'd to override the blanket package init).

Verification

./gradlew :bin:map-isolate:nativeCompile now succeeds locally (Finished generating 'map-isolate' in 2m 46s, 125 MB executable produced).

@mworzala mworzala merged commit b0db576 into main Jun 14, 2026
2 checks passed
@mworzala mworzala deleted the fix/native-image-loginlistener-securerandom branch June 14, 2026 18:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant