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

I get NullPointerException when I use long value and null in ternary operator

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P4 P4
    • None
    • 8u51
    • core-libs
    • x86_64
    • windows_7

      FULL PRODUCT VERSION :
      C:\Users\Tim>java -version
      java version "1.8.0_65"
      Java(TM) SE Runtime Environment (build 1.8.0_65-b17)
      Java HotSpot(TM) 64-Bit Server VM (build 25.65-b01, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Windows 10 x64

      A DESCRIPTION OF THE PROBLEM :
      Try running this:

      public class Main {

      public static void main(String[] args) {
      Long var = null;
      System.out.println("text" == null ? 0L : var);
      }
      }

      I only get NullPointerException when i use a Number value.
      To fix this, I need to cast the long value like this:
          Long var = null;
          System.out.println("text" == null ? (Long)0L : var);




      REPRODUCIBILITY :
      This bug can be reproduced always.

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

              Created:
              Updated:
              Resolved: