In an openjdk mailing list post this week, Oracle's Mark Reinhold, chief architect of the Java platform group, called encapsulation a part of the modularization of Java 9, which is the upgrade's key feature. By default, these internal APIs would not be accessible to code outside the JDK. "This change will improve the integrity of the platform, since many of these internal APIs define privileged, security-sensitive operations. In the long run it will also reduce the costs borne by the maintainers of the JDK itself and by the maintainers of libraries and applications that, knowingly or not, make use of these non-standard, unstable, and unsupported internal APIs."

Reinhold added that it was "well-known that some popular libraries make use of these internal APIs, such as sun.misc.Unsafe, to invoke methods that would be difficult, if not impossible, to implement outside of the JDK."

To ensure broad testing and adoption of the Java release, Oracle is proposing to deal with these "critical" APIs in the following manner: If there is a supported replacement in JDK 8, then it will be encapsulated; if it does not have a supported replacement in JDK 8, then it will be encapsulated in JDK 9 (Java 9), so it remains accessible to outside code. If there is a supported replacement in JDK 9, then the APIs would be deprecated in JDK 9, encapsulated, and possibly be removed in JDK 10, Reinhold said.

Reinhold's proposal is "interesting," said analyst John Rymer, of Forrester Research. "I think the ball is back in the third-party vendors' courts to be more specific about the impending disaster. Reinhold's response suggests that Oracle has them covered, and so where are the gaps?"

The JEP does mention some risks and assumptions of the encapsulation plan. "If some widely-used critical internal API is not identified by the time that JDK 9 is released, then applications that depend upon it will fail. The short-term workaround for such a situation would be for the end user to expose the API via the above-mentioned command-line flag; in the longer term, in a JDK 9 update release the API could be moved to the jdk.internal module and exported for external use."

This story, "Java devs rejoice as private APIs stay in -- for now" was originally published by
InfoWorld.