Java · Easy · Free
Helpful NullPointerExceptions — how to read the detail message in production?
JavaCore JavaFresher
Helpful NullPointerExceptions
JDK 14+ enriches NPE messages with which variable was null in the expression chain—dramatically faster root cause in logs without debugger.
- Enabled by default; disable with
-XX:-ShowCodeDetailsInExceptionMessagesif info leakage concern. - Shows method, field, and array index in chain.
- Still fix null safety—don't rely on messages in API contracts.
- Works with records and compact stack traces.
java
// NPE message example:
// Cannot invoke "String.length()" because "user.getName()" is nullProduction: pair with structured logging of user id—not the null field alone for PII.