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

XMLWordPrintable

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

      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.

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

              Created:
              Updated:
              Resolved: