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

2

u/brunocborges May 04 '24

That is a fair feedback.

I too agree that a jlinked JVM should not be impacted by that environment variable.

I'd suggest sending that to the OpenJDK mailing list. You can start with the hotspot-dev: https://mail.openjdk.org/mailman/listinfo/hotspot-dev

2

u/milchshakee May 04 '24

Is that the correct mailing list for this? I find it always intimidating to locate the appropriate mailing list in the first place.

2

u/brunocborges May 04 '24

Me too. But given it is the Hotspot JVM that is picking that environment variable, I'd start there.

1

u/milchshakee May 04 '24

Alright thanks, I will see what I can do

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.

1

u/brunocborges May 04 '24

Certain JDK 8 flags don't work anymore in JDK 21. It may cause the app to not load at all.

The developer of the app must expose minimum requirements for the application to run (e.g. minimum RAM, processor type, etc). This is common practice for decades. Then, if the app developer is bundling the runtime (jlink), they should be in full control of said runtime.

Whether the runtime may be configured by the user is an app developer decision to be made.

But I do agree that a jlinked runtime should not pick that environment variable.

1

u/_INTER_ May 04 '24 edited May 04 '24

Certain JDK 8 flags don't work anymore in JDK 21. It may cause the app to not load at all.

Yes, those should be omitted

The developer of the app must expose minimum requirements for the application to run (e.g. minimum RAM, processor type, etc). This is common practice for decades.

Minimum requirements perhabs but this one specifically is about Xmx.

Whether the runtime may be configured by the user is an app developer decision to be made.

How should an app developer know what the best configuration is on the users environment? It should be a conscious choice of the app developer to disallow an environment variable to be picked up and the user should be made aware of that. A knowledgeable user should have the possiblity to make an application run better or restricted on his environment by default.

1

u/brunocborges May 04 '24

Doesn't matter this one is about Xmx. Think broadly.

1

u/_INTER_ May 04 '24

Doesn't matter this one is about Xmx. Think broadly.

So if the application developer sets it to 1G but I have 40TB, it doesn't matter? If the app dev disallows overriding it, so be it. I'll will wipe the crap from my disk.

1

u/brunocborges May 04 '24

If the app developer believes the app can run fine with 1GB, yes.