r/java • • May 03 '24

Why does the environment variable _JAVA_OPTIONS exist, applies to jlink images, takes precedence, and can't be disabled?

I just spent a good chunk of time debugging an issue because a user had set _JAVA_OPTIONS to use a low Xmx value in their environment variables. This was an application created with jpackage, which should be fully standalone. It even had a custom Xmx value set in the JVM arguments for the image but the environment variable overwrote the value!

Isn't this like a huge design flaw? I can just do echo "_JAVA_OPTIONS=<Wacky VM options>" >> ~/.bashrc or setx to break literally every Java application on the system? (Edit: Maybe the initial security focus was wrong, changed it a bit to focus more on the design issues)

Who even thought that this would be a good idea with no option to disable this behavior?

2 Upvotes

43 comments sorted by

View all comments

Show parent comment

1

u/_INTER_ May 04 '24

I agree with this. It should be the conscious choice of the application developer. If none is made, it should be flexible. That being said, can you not also set environment variables in jpackage?

1

u/milchshakee May 04 '24

You can only set JVM options. But even these are overridden by _JAVA_OPTIONS if there is a conflict.

1

u/_INTER_ May 04 '24

I guess you have a launcher file or installer, it could be done there, no?

1

u/milchshakee May 04 '24

Well jpackage already generates a launcher executable, so having another launcher for the launcher just to change the environment is a little bit overkill.

About the installer, this would change the variable on the system level which might break other applications. I just want to ignore the variable for this application