Search code examples
javajavaoptions

Is JAVA_OPTIONS boolean case sensitive?


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?


Solution

  • 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.