Skip to content

Suppress sun.misc.Unsafe and JNA native-access warnings on Java 23+#1408

Draft
nevingeorgesunny wants to merge 1 commit into
jenkinsci:masterfrom
nevingeorgesunny:fix-java25-unsafe-native-access-warnings
Draft

Suppress sun.misc.Unsafe and JNA native-access warnings on Java 23+#1408
nevingeorgesunny wants to merge 1 commit into
jenkinsci:masterfrom
nevingeorgesunny:fix-java25-unsafe-native-access-warnings

Conversation

@nevingeorgesunny

@nevingeorgesunny nevingeorgesunny commented Jun 19, 2026

Copy link
Copy Markdown

Summary

On Java 24+, XStream's SunUnsafeReflectionProvider triggers a terminally deprecated sun.misc.Unsafe warning by default (JEP 498). JNA similarly warns about restricted native access on Java 23+. Both warnings are harmless — no tests fail — but they produce significant noise in test output (2,000+ warnings per PCT/ATH build run on Java 25).

This adds a Java 23+ Maven profile that injects two JVM flags into Surefire's argLine via late-binding @{jenkins.java23Plus}:

  • --sun-misc-unsafe-memory-access=allow — silences XStream sun.misc.Unsafe deprecation warning (x-stream/xstream#362)
  • --enable-native-access=ALL-UNNAMED — silences JNA restricted native-access warning

The flags are gated behind a [23,) profile so they are never passed to Java 17 or 21, where they would cause an Unrecognized VM option error and break the build.

On Java 24+, XStream's SunUnsafeReflectionProvider triggers a terminally
deprecated sun.misc.Unsafe warning by default (JEP 498). JNA similarly
warns about restricted native access on Java 23+. Both warnings pollute
test output on Java 25 but are harmless — no tests fail.

This adds a Java 23+ profile that injects two JVM flags into Surefire's
argLine via late-binding @{jenkins.java23Plus}:
- --sun-misc-unsafe-memory-access=allow (silences XStream Unsafe warning)
- --enable-native-access=ALL-UNNAMED (silences JNA native-access warning)

The flags are gated behind a [23,) profile so they are never passed to
Java 17 or 21, where they would cause an unrecognized VM option error.

Relates to: https://issues.jenkins.io/browse/JENKINS-65837

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

@jglick jglick left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the short term I think this makes sense. We do still need to get XStream to behave properly on 23+ (especially before it breaks by default on 26+ or whatever it is 😱), and we do need to find ways to eliminate JNA (and JNI) in normal usage.

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.

2 participants