I discussed long-awaited and highly appreciated improvements to NullPointerException (NPE) messages in the posts "Better Default NullPointerException Messages Coming to Java?" and "Better NPE Messages in JDK 14". When this JEP 358-driven feature was added to JDK 14, a developer who wanted to benefit from these more insightful NPE messages needed to explicitly state that desire by passing the argument -XX:+ShowCodeDetailsInExceptionMessages
to the Java launcher (java
).
The JDK 15 Early Access Build #29 was released this week and makes the use of better NPE messages automatic. The release notes associated with this early access build state: "The default of the flag ShowCodeDetailsInExceptionMessages
was changed to 'true
'. The helpful NullPointerException
messages of JEP 358 are now printed by default. The messages contain snippets of the code where the NullPointerException
was raised."
The next screen snapshot demonstrates that the helpful NullPointerException
details are provided automatically with JDK 15 Early Access Build #29.
The release notes also point out that one potential risk of having the "helpful" NullPointerException
messages written by default is the accidental exposure of sensitive details. The release notes warn: "App deployers should double check the output of their web applications and similar usage scenarios. The NullPointerException message could be included in application error messages or be displayed by other means in the app. This could give remote attackers valuable hints about a potential vulnerable state of the software components being used."
The next screen snapshot demonstrates that automatic presentation of helpful NullPointerException
details can be disabled via the use of java
launcher option -XX:-ShowCodeDetailsInExceptionMessages
(and the old -XX:+ShowCodeDetailsInExceptionMessages
is still supported even though this is now the default):
One on the interesting consequences of the JDK-8233014 change to make helpful NullPointerException
messages enabled by default is that there will undoubtedly be some Java developers pleasantly surprised when they upgrade to JDK 15 and start seeing suddenly far more useful messages when encountering the ubiquitous NullPointerException
.