Is JAVA_OPTIONS boolean case sensitive?

582 Views Asked by At

I am trying to set JAVA_OPTIONS to my application

-Djava.net.preferIPv4Stack=true

Can I also set it as -Djava.net.preferIPv4Stack=True with the capital T? Does the case matter?

2

There are 2 best solutions below

0
On BEST ANSWER

This is the occasion when the difference between being a good programmer and being a good designer matters:

  • A good programmer will make sure that this parametrization (-Djava.net.preferIPv4Stack=True) works in the current environment: For example, if you are using Open JDK 15, you shall browse the source code and you will see that the class java.net.PlainSocketImpl, where that parameter is used, delegates on Boolean.parseBoolean, which does a case-insensitive parsing.

  • A good designer, instead, will make sure to set a parametrization such that will work on every environment (Open JDK, Oracle JDK, version 15, future versions, Windows, Linux, etc), by sticking to the public documentation, which states that only "true" or "false" (or absent) values must be used.

Summarizing: If you are using Open JDK 15, there is no difference between "True" or "true" values, but you cannot be sure that in future versions such difference will matter. I recommend you to stick to the docummented allowed values.

0
On

To read boolean system properties, you'd typically use

Boolean.getBoolean("argument.name");

Which:

Returns true if and only if the system property named by the argument exists and is equal to the string "true". (Beginning with version 1.0.2 of the JavaTM platform, the test of this string is case insensitive.)

(Reference)

It's really up to the developer (which can also use System.getProperty then cast the result to boolean, in his own way), but I'd say for most cases, I'd assume it's case insensitive.