JEP draft: Prepare to Restrict The Use of JNI

Constantin Christoph 4evnyuij at gmail.com
Mon Aug 28 22:04:08 UTC 2023


But now, what if instead of making an application using a JNI-using
library, I am making a library using JNI myself? I have absolutely zero
control over whether JNI will work when my library is used, it is up to the
user of the library to figure out that a flag needs to be added to the
startup arguments. Now imagine that a few more libraries are in between my
library (using JNI), and the end user. The JNI-heavy feature is now behind
several layers of abstraction, and may not even get called until a very
niche use case happens, and if the startup argument isn't present at that
time, the program crashes. A notice from me regarding my library's usage of
JNI *will* be overlooked at some point, and you can't always feasibly catch
errors like this in testing.

This is just another example of what will inevitably happen when these
changes are in full effect, and the tradeoff is just not worth the hours of
lost developer time that will undoubtedly need to be sacrificed to fix
issues like these.

As mentioned, a fix to issues like these would be to either
- Make the JNI flag a module setting; or
- Make JNI usage opt-out instead of opt-in; or
- Don't restrict JNI usage at all.

This is my final stance on the subject manner: The changes should not be
made in their current state. You just cannot change such an old interface
that drastically, a lot of libraries will break, and a lot of developers
will be disappointed.

Constantin

Am Mo., 28. Aug. 2023 um 23:36 Uhr schrieb Ron Pressler <
ron.pressler at oracle.com>:

>
>
> > On 28 Aug 2023, at 21:58, Spam mail <4evnyuij at gmail.com> wrote:
> >
> > You don’t need to add a flag to the startup args to use a library..?
> >
> > The classpath manifest entry exists, and shading is still a very
> prominent thing (although not the best practise). A medium-sized
> application with ~7 libraries can be launched with java -jar app.jar just
> fine, if you configure your build correctly.
>
> I said a flag or a manifest attribute or something even more complicated
> (by which I referred to shading). Therefore, requiring another flag or a
> manifest attribute won't make building or launching that 7-library program
> significantly harder, however you choose to build it or launch it.
>
> — Ron
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/jdk-dev/attachments/20230829/c7100305/attachment.htm>


More information about the jdk-dev mailing list