Skip to content

CAUTION: This site hosts draft documentation for the next release. For published content of the latest release, visit www.eclipse.org/openj9/docs

-XX:[+|-]ShowCodeDetailsInExceptionMessages

This OpenJDK HotSpot option enables or disables the feature that displays the details of a NullPointerException generated by a VM. This option is recognized by Eclipse OpenJ9™ and provided for compatibility.

Syntax

    -XX:[+|-]ShowCodeDetailsInExceptionMessages
Setting Effect Default
-XX:+ShowCodeDetailsInExceptionMessages Enable Start of content that applies to Java 15 and later yes End of content that applies to Java 15 and later
-XX:-ShowCodeDetailsInExceptionMessages Disable Start of content that applies to Java 14 yes End of content that applies to Java 14

Explanation

A NullPointerException might include a message if a message was specified in the NullPointerException constructor or a null message if no message was specified in the constructor. A NullPointerException that is generated by a VM also has a null message. These messages do not have details of the reason for the exceptions thrown. A NullPointerException also includes a stack trace that contains the method, file name, and line number where the exception occurred. However, a single line of code might contain several access paths. Each of these paths might be the source of that exception, and it is difficult to identify the path that is the root cause of the exception.

JEP 358: Helpful NullPointerExceptions provides extended messages when a NullPointerException is generated by a VM. You can enable this feature with the -XX:+ShowCodeDetailsInExceptionMessages option, which is a part of this JEP 358. When this feature is enabled and the VM throws a NullPointerException, a detailed message with the action that was not completed because of this exception and the reason for this exception is displayed. For example, in the following message, Cannot read field "c" is the action that was not completed and because "a.b" is null is the root cause of the exception.

Exception in thread "main" java.lang.NullPointerException: Cannot read field "c" because "a.b" is null
    at Prog.main(Prog.java:5)