JDK-8057897 : NullPointerException message should name the null variable.
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.lang
  • Affected Version: 8u20
  • Priority: P4
  • Status: Resolved
  • Resolution: Duplicate
  • OS: linux
  • CPU: x86_64
  • Submitted: 2014-09-03
  • Updated: 2020-01-27
  • Resolved: 2020-01-27
Related Reports
Duplicate :  
Relates :  
Description
A DESCRIPTION OF THE REQUEST :
It's not uncommon that I'll write code that deferences several variables in one line; usually this is a method call like this :

doSomething(foo.getBar(), baz.getQuux(), one, two, three.toString());

If one of those variables is null, I get a NPE. This is a bother to debug though since I don't know which it is. I need to use a debugger or change the code to put all the deferences on separate lines, and that can be pretty slow when deploying web applications or other contained applications.

The system knows which variable was null, so if it could put that in the detail message it would be a quick help to debugging.

This is a pretty minor thing but from time to time it would be really helpful.

JUSTIFICATION :
It would speed up debugging in cases where multiple variables are dereferenced in one line of code.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
NullPointerException would display the offending variable:

Exception: RuntimeException
  java.lang.NullPointerException ("foo" was null)
at blah.blah.blah.SomeClass.someMethod(SomeClass.java:123)
...
ACTUAL -
Detail message is plain


Comments
The library does not have enough information to include in the exception.
11-05-2017