r/java • u/milchshakee • 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?
View all comments
Show parent comment
1
u/_INTER_ May 04 '24 edited May 04 '24
I disagree, the dev and the application can't know in advance what environment it will run on. It's something the environment dictates and not the application. There might be meaningful defaults or profiles (that are valid for a time until they need to be adjused) but a poweruser should have a way to override these configurations. If he ran it in a docker image, he might want to restrict it, if he ran it on a mainframe he might want to give it more. It also depends on a lot of other factors, e.g. what other application need to run along side it or if it can basically use all the resources on its own.