Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8057897

NullPointerException message should name the null variable.

    XMLWordPrintable

Details

    • Enhancement
    • Resolution: Duplicate
    • P4
    • None
    • 8u20
    • core-libs
    • x86_64
    • linux

    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

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: