Preparing for JNI Restrictions in JDK 24
With the release of Java Development Kit (JDK) 23 just around the corner, the focus has already shifted toward JDK 24, set for a March 2025 debut. Among the first features targeted for JDK 24 is a significant move toward tightening how Java handles the Java Native Interface (JNI). This feature introduces warnings that aim to prepare developers for future restrictions on using JNI, signaling an important shift in the evolution of Java. As these changes unfold, developers are encouraged to pay attention to these updates to stay ahead of any compatibility or security issues.
Watch @gsaab present the #JVMLS keynote on the state of #Java in 2024. https://t.co/kD0HP2adjQ
— Java (@java) August 21, 2024
Why JNI Restrictions Matter
JNI has long been the standard for enabling Java code to interact with native code. However, as Java evolves, the need to enhance the security and integrity of these interactions is becoming more critical. JDK 24’s new warnings regarding JNI use represent the initial phase of a plan that will eventually see stricter default restrictions on native code interactions. This change is a proactive step to mitigate risks, particularly as Java’s ecosystem grows more complex and expansive.
The planned alignment of these warnings with the Foreign Function and Memory (FFM) API, introduced in JDK 22, ensures consistent messaging and offers developers an alternative pathway. The end goal is to streamline the transition for developers who will eventually need to migrate away from relying heavily on JNI, ensuring smoother interoperability while maintaining security best practices.
Other Potential Features in JDK 24
Beyond the critical updates to JNI handling, JDK 24 could see several other significant features, many of which are currently being previewed in JDK 23:
- Class-File API: Enhances capabilities for parsing, generating, and transforming Java class files.
- Stream Gatherers: Adds improvements to the stream API, allowing for more customized intermediate operations.
- Module Import Declarations: Simplifies importing all packages exported by a module, reducing complexity for library reuse.
- Structured Concurrency: Introduces a more straightforward approach to managing concurrent programming.
- Primitive Types in Patterns, Instanceof, and Switch: Expands pattern matching by allowing primitive type patterns across all pattern contexts.
- Vector API (Eighth Incubation): Advances vector computations, enabling better runtime optimization on supported CPU architectures.
Additional features, such as ahead-of-time class loading for faster Java startups and string templates (previously previewed in JDK 21 and 22), could also make it into JDK 24 depending on ongoing development efforts.
Understanding the Release Cadence and Adoption Trends
As with JDK 23, JDK 24 will be a non-long-term support (LTS) release, receiving only six months of Premier-level support from Oracle. Traditionally, non-LTS releases have seen lower adoption rates, as organizations often prefer the stability of LTS versions. The most recent LTS release, JDK 21, launched in September 2023 and is set to receive at least five years of support, making it the preferred choice for enterprises focused on long-term projects.
The next LTS release, JDK 25, scheduled for September 2025, is expected to draw greater attention, meaning that JDK 24 might primarily serve as a stepping stone for developers looking to experiment with upcoming features before they are finalized in an LTS version.
Preparing for Future Java Changes
For developers and organizations relying heavily on JNI, JDK 24’s warnings are more than just advisory—they’re a signal to start adapting now. Exploring alternatives like the FFM API and rethinking native code usage should be a priority. Preparing ahead of time will not only prevent potential issues down the line but will also position your applications for a smoother transition when future Java releases enforce stricter rules around native code interoperability.
JDK 23 and JDK 24: What We Know So Far https://t.co/vhG5kOVYgQ by @mpredli
— InfoQ (@InfoQ) August 22, 2024
What’s Your Take?
Are you ready to adapt your codebase for these upcoming changes? We’d love to hear how you’re preparing for the new restrictions and what features in JDK 24 interest you the most. Share your thoughts in the comments below!
Photo by Gregory Hayes on Unsplash