JEP draft: Prepare to Restrict The Use of JNI
Alex Buckley
alex.buckley at oracle.com
Tue Aug 29 16:14:37 UTC 2023
On 8/29/2023 8:47 AM, Quân Anh Mai wrote:
> There is a huge difference between --add-opens and
> --enable-native-access here. While the sole purpose of --add-opens is to
> break encapsulation and open implementation details, dependence on which
> is a major factor causing the friction of migration from 8 to 9, the
> purpose of JNI is not to break anything, but to simply enable native
> accesses from Java. While encapsulation breakage is possible in JNI,
> equating it as its sole purpose seems illogical. As a result, forcing
> the users to treat it similarly as --add-opens and friends seems not to
> be reasonable to me.
We are not saying that breaking encapsulation is the sole purpose of
JNI. We are saying that the use of native code, while sometimes the only
way to do something, is risky. The JEP identifies four risks --
https://openjdk.org/jeps/8307341#Motivation -- of which the first two --
undefined behavior and bad buffers -- are by far the worst.
We are then saying something further: the risks are so high that the
user should explicitly agree to take them.
Alex
More information about the jdk-dev
mailing list