Skip to content

Commit 92540f3

Browse files
xerialclaude
andauthored
Document JDK 24+ native access requirements (#702)
Add documentation for JEP 472 native access requirements that affect users running snappy-java on JDK 24 or later. Since snappy-java uses JNI to load native libraries, applications running on JDK 24+ must add the --enable-native-access=ALL-UNNAMED JVM flag. Per JEP 472 guidance, this is the application developer's responsibility (not the library's). The new section includes: - Clear explanation of the requirement - Examples for Maven, Gradle, sbt, and command-line usage - Warning message examples users will encounter - Rationale based on JEP 472's "integrity by default" policy No code changes are needed - this is purely documentation to help users understand and address the warnings they see on JDK 24+. Fixes #689 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude <[email protected]>
1 parent 31b0ca5 commit 92540f3

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

README.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,63 @@ implementation("org.xerial.snappy:snappy-java:(version)")
6363
libraryDependencies += "org.xerial.snappy" % "snappy-java" % "(version)"
6464
```
6565

66+
## JDK 24+ Native Access Requirements
67+
68+
Starting with JDK 24, Java has introduced restrictions on native method access through [JEP 472: Prepare to Restrict the Use of JNI](https://openjdk.org/jeps/472). Since snappy-java uses JNI to load native libraries for high-performance compression, applications running on **JDK 24 or later** must enable native access.
69+
70+
### Required JVM Flag
71+
72+
When running on JDK 24+, add the following JVM flag to your application:
73+
74+
```bash
75+
--enable-native-access=ALL-UNNAMED
76+
```
77+
78+
### Examples
79+
80+
**Running a JAR:**
81+
```bash
82+
java --enable-native-access=ALL-UNNAMED -jar your-application.jar
83+
```
84+
85+
**Maven:**
86+
```xml
87+
<plugin>
88+
<groupId>org.apache.maven.plugins</groupId>
89+
<artifactId>maven-surefire-plugin</artifactId>
90+
<configuration>
91+
<argLine>--enable-native-access=ALL-UNNAMED</argLine>
92+
</configuration>
93+
</plugin>
94+
```
95+
96+
**Gradle:**
97+
```gradle
98+
tasks.withType(Test) {
99+
jvmArgs '--enable-native-access=ALL-UNNAMED'
100+
}
101+
```
102+
103+
**sbt:**
104+
```scala
105+
javaOptions += "--enable-native-access=ALL-UNNAMED"
106+
```
107+
108+
### Why is this needed?
109+
110+
Per JEP 472's policy of "integrity by default," it is the application developer's responsibility (not the library's) to explicitly enable native access. This change improves security by making native operations visible and controlled at the application level.
111+
112+
Without this flag on JDK 24+, you will see warnings like:
113+
```
114+
WARNING: A restricted method in java.lang.System has been called
115+
WARNING: java.lang.System::load has been called by org.xerial.snappy.SnappyLoader
116+
WARNING: Use --enable-native-access=ALL-UNNAMED to avoid a warning for callers in this module
117+
```
118+
119+
These warnings will become errors in future JDK releases.
120+
121+
**Note:** This requirement only applies to JDK 24 and later. Earlier JDK versions (8-23) do not require this flag.
122+
66123

67124
## Usage
68125
First, import `org.xerial.snapy.Snappy` in your Java code:

0 commit comments

Comments
 (0)