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

[lworld] [lw3] NPE thrown when attempting to write null to a null-free array has incorrect error message

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P3
    • Resolution: Fixed
    • Affects Version/s: repo-valhalla
    • Fix Version/s: None
    • Component/s: hotspot
    • Labels:

      Description

      The following code:


      public class NullFreeArray {
          static primitive class Point {
      int x = 0, y = 0;
          }

          static void setNull(Object[] a) {
      try {
      a[0] = null;
      } catch(Throwable t) {
      System.out.println(t);
      }
          }
          
          public static void main(String[] args) {
      Point[] a = new Point[10];
      setNull(a);
          }
      }


      produces this output:

      java.lang.NullPointerException: Cannot store to object array because "<parameter1>" is null

      However, <parameter1> in method setNull() is not null, the NPE is caused by the null reference that the code tries to write to the null-free Point array.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              fparain Frederic Parain
              Reporter:
              fparain Frederic Parain
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: