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

NullPointerException from method reference on null object

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P4
    • Resolution: Not an Issue
    • Affects Version/s: 8u45
    • Fix Version/s: None
    • Component/s: tools
    • Labels:
    • Subcomponent:
    • CPU:
      x86_64
    • OS:
      windows_7

      Description

      FULL PRODUCT VERSION :

      java version "1.8.0_45"
      Java(TM) SE Runtime Environment (build 1.8.0_45-b15)
      Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)


      A DESCRIPTION OF THE PROBLEM :

      The following simple example code leads to a NullPointerException:

      import java.util.function.Supplier;

      public class MethodReferenceNpeTest {

      public static void main(String[] args) {
      Object object = createObject();
      Supplier<String> supplier = object::toString;
      if (object != null) {
      System.out.println(supplier.get());
      }
      }

      private static Object createObject() {
      return null;
      }

      }

      RESULT :

      After compiling it with javac and running it, following NPE occurs:

      Exception in thread "main" java.lang.NullPointerException
      at de.fhg.iwes.ui.vpp.MethodReferenceNpeTest.main(MethodReferenceNpeTest.java:9)

      -- Compiling the same code with the eclipse compiler doesn't lead to a NPE

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                mcimadamore Maurizio Cimadamore
                Reporter:
                aliebelt Andreas Liebelt
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: