What may come in Java 22
Published: 2024-01-03 19:27:22

Scheduled for a General Availability release in March 2024, there are currently no specific JEPs targeted for inclusion in JDK 22. Nevertheless, an analysis of various JEP candidates and drafts, particularly those that have been submitted, allows for a preliminary identification of potential JEPs that may be incorporated into [JDK 22](https://jdk.java.net/22/).

[**JEP 447**](https://openjdk.org/jeps/447), "Statements before `super()`," operating under Project Amber, proposes the allowance of statements that do not reference an instance being created to appear before the `this()` or `super()` calls in a constructor. Additionally, it aims to preserve existing safety and initialization guarantees for constructors. Gavin Bierman, a consulting member of technical staff at Oracle, has furnished an initial specification of this JEP for the Java community's review and feedback.

[**JEP 435**](https://openjdk.org/jeps/435), the "Asynchronous Stack Trace VM API," categorized as a feature JEP, seeks to define an efficient API for obtaining asynchronous call traces for profiling from a signal handler, providing information on both Java and native frames.

[**JEP 401**](https://openjdk.org/jeps/401), now named "Null-Restricted Value Object Storage (Preview)" (previously known as Primitive Classes Preview) and operating under Project Valhalla, introduces developer-declared primitive classes, which are specialized forms of value classes as defined by the Value Objects API. These classes define new primitive types.

[**JEP Draft 8307341**](https://openjdk.org/jeps/8307341), "Prepare to Restrict The Use of JNI," proposes to limit the use of the inherently unsafe Java Native Interface (JNI) in conjunction with the use of restricted methods in the Foreign Function & Memory (FFM) API, expected to become a final feature in JDK 22. Starting in JDK 22, the Java runtime will issue warnings about the use of JNI unless an FFM user enables unsafe native access on the command line. Subsequent releases after JDK 22 are anticipated to throw exceptions instead of warnings when using JNI.

[**JEP Draft 8310626**](https://openjdk.org/jeps/454), the "Foreign Function & Memory API," aims to finalize this feature after two rounds of incubation and three rounds of preview. It has undergone successive stages, including JEP 412 (Foreign Function & Memory API Incubator) in JDK 17, JEP 419 (Foreign Function & Memory API Second Incubator) in JDK 18, JEP 424 (Foreign Function & Memory API Preview) in JDK 19, JEP 434 (Foreign Function & Memory API Second Preview) in JDK 20, and the upcoming JEP 442 (Foreign Function & Memory API Third Preview) in JDK 21. Notable improvements since the last release encompass a new Enable-Native-Access manifest attribute, enabling executable JARs to call restricted methods without the --enable-native-access flag; the ability for clients to programmatically construct C function descriptors, avoiding platform-specific constants; enhanced support for variable-length arrays in native memory; and support for multiple charsets in native strings.

[**JEP Draft 8288476**](https://bugs.openjdk.org/browse/JDK-8288476), "Primitive types in patterns, instanceof, and switch (Preview)," proposes to enhance pattern matching by allowing primitive type patterns in all pattern contexts, aligning the semantics of primitive type patterns with instanceof, and extending switch to permit primitive constants as case labels.

[**JEP Draft 8277163**](https://openjdk.org/jeps/8277163), "Value Objects (Preview)," a feature JEP under the auspices of Project Valhalla, proposes the creation of value objects—identity-free value classes specifying the behavior of their instances. This draft is related to JEP 401, "Primitive Classes (Preview)," which is still in Candidate status.

[**JEP Draft 8313278**](https://openjdk.org/jeps/8313278), "Ahead of Time Compilation for the Java Virtual Machine," proposes to enhance the Java Virtual Machine with the ability to load Java applications and libraries compiled to native code, facilitating faster startup and baseline execution.

[**JEP Draft 8312611**](https://openjdk.org/jeps/8312611), "Computed Constants," introduces the concept of computed constants—immutable value holders initialized at most once. This feature provides the performance and safety benefits of final fields while offering greater flexibility in terms of initialization timing. This feature is set to debut as a preview API.

[**JEP Draft 8283227**](https://openjdk.org/jeps/8283227), "JDK Source Structure," classified as an informational JEP, outlines the overall layout and structure of the JDK source code and related files in the JDK repository. This JEP aims to assist developers in adapting to the source code structure as described in JEP 201, "Modular Source Code," delivered in JDK 9.

[**JEP Draft 8280389**](https://bugs.openjdk.org/browse/JDK-8280389?page=com.atlassian.streams.streams-jira-plugin%3Aactivity-stream-issue-tab), "ClassFile API," proposes to provide an API for parsing, generating, and transforming Java class files. Initially serving as an internal replacement for ASM, the Java bytecode manipulation and analysis framework, in the JDK, this JEP plans to eventually open as a public API. Brian Goetz, Java language architect at Oracle, characterizes ASM as an "old codebase with plenty of legacy baggage" and provides background information on how this draft will evolve and ultimately replace ASM.

[**JEP Draft 8278252**](https://openjdk.org/jeps/8278252), "JDK Packaging and Installation Guidelines," an informational JEP, aims to provide guidelines for creating JDK installers on macOS, Linux, and Windows. The goal is to reduce the risks of collisions among JDK installations by different providers and promote a better experience when installing update releases of the JDK by formalizing installation directory names, package names, and other installer elements that may lead to conflicts.

It is anticipated that Oracle will soon commence the targeting of JEPs for inclusion in JDK 22.