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

Java compiler allow to return null in a method signature that returns int

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P4 P4
    • None
    • 6u26
    • tools
    • x86
    • windows_7

      FULL PRODUCT VERSION :
      java version "1.6.0_24"
      Java(TM) SE Runtime Environment (build 1.6.0_24-b07)
      Java HotSpot(TM) 64-Bit Server VM (build 19.1-b02, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows [Version 6.1.7601]

      A DESCRIPTION OF THE PROBLEM :
      The following code should not compile, however it does compile and throws NullPointerException

      public int foo()
      {
         return 1==1 ? null : 1;
      }

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      See description

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      This code should not compile. I should not be able to return null if the method signature expects int
      ACTUAL -
      Code was compiled without any warning or error.At runtime this code produces NullPonterException

      REPRODUCIBILITY :
      This bug can be reproduced always.

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

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: