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

assignment to array's length field causes NullPointException

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      1.0.2
    • CPU:
      sparc
    • OS:
      solaris_2.5
    • Verification:
      Not verified

      Description

      The following code causes a NullPointerException in the compiler. The critical
      line is the attempt to assign a length to the array. This should generate a compiler
      error -- the exception gives no help in finding the illegal construct.

      class t {
          void foo() {
              int[] a = new int[10];
              int i = a.length;
              a.length = 12;
          }
      }

      Here is the stack trace:

      java.lang.NullPointerException
              at sun.tools.tree.FieldExpression.inlineLHS(FieldExpression.java:317)
              at sun.tools.tree.BinaryAssignExpression.inlineValue(BinaryAssignExpression.java:62)
              at sun.tools.tree.BinaryAssignExpression.inline(BinaryAssignExpression.java:59)
              at sun.tools.tree.ExpressionStatement.inline(ExpressionStatement.java:51)
              at sun.tools.tree.CompoundStatement.inline(CompoundStatement.java:65)
              at sun.tools.javac.SourceField.inline(SourceField.java:293)
              at sun.tools.javac.SourceField.code(SourceField.java:367)
              at sun.tools.javac.SourceClass.compileClass(SourceClass.java:564)
              at sun.tools.javac.SourceClass.compile(SourceClass.java:527)
              at sun.tools.javac.Main.compile(Main.java:193)
              at sun.tools.javac.Main.main(Main.java:289)
      error: An exception has occurred in the compiler; please file a bug report (###@###.###).

      I suppose I'm not surprised that the only read-only field in the universe is
      handled differently.

      [mchan 4/30/96]
      Customer from BEA Systems is encountering the same bug. Apparently, the bug still
      exists on Java 1.0.1.


      I know the following Java program is invalid, but it should generate
      an error instead of the NullPointerException.

      I am using Java 1.0 on Solaris 2.5 with SS5. The same bug exists on
      Java 1.0.1.

      class V
      {
              public static void main( String args[] )
              {
                      args.length = 5;
              }
      }

      java.lang.NullPointerException
              at sun.tools.tree.FieldExpression.inlineLHS(FieldExpression.java:317)
              at sun.tools.tree.BinaryAssignExpression.inlineValue(BinaryAssignExpression.java:62)
              at sun.tools.tree.BinaryAssignExpression.inline(BinaryAssignExpression.java:59)
              at sun.tools.tree.ExpressionStatement.inline(ExpressionStatement.java:51)
              at sun.tools.tree.CompoundStatement.inline(CompoundStatement.java:65)
              at sun.tools.javac.SourceField.inline(SourceField.java:293)
              at sun.tools.javac.SourceField.code(SourceField.java:367)
              at sun.tools.javac.SourceClass.compileClass(SourceClass.java:564)
              at sun.tools.javac.SourceClass.compile(SourceClass.java:527)
              at sun.tools.javac.Main.compile(Main.java:193)
              at sun.tools.javac.Main.main(Main.java:289)
      error: An exception has occurred in the compiler; please file a bug report (###@###.###).
      1 error
      *** Error code 1

        Attachments

          Activity

            People

            Assignee:
            tlindholsunw Timothy Lindholm (Inactive)
            Reporter:
            duke J. Duke (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: