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

Illegal array reference expression allowed.

    XMLWordPrintable

    Details

    • Subcomponent:
    • CPU:
      sparc
    • OS:
      solaris_2.5.1

      Description


      allan.jacobs@Eng 1997-03-27

      The Java Language Specification (15.12) says that the array in an
      array access expression can be a name or any primary expression that
      is not an array creation expression. However, javac allows this
      construct. Included are sample codes that behave as one might expect
      and code that malfunctions. Both are derivatives of Modena test
      c1512104.



      algol% javac f1512104.java
      algol% javac e1512104.java
      algol% java -Djava.compiler=none e1512104
      i1=-1 b1=true
      i1=-1 b2=true
      algol% java -Djava.compiler=none f1512104
      b1=false
      b2=false
      algol% cat e1512104.java
      class e1512104 {
        public static void main( String[] argv ) {
          boolean b1 = false;
          boolean b2 = false;
          int i1 = -1;
          try {
          i1 = (new int[1])[1];
          }
          catch(ArrayIndexOutOfBoundsException e) { b1=true;}
          System.out.println("i1="+i1+" b1="+b1);
          try {
          i1 = (new int[0])[0];
          }
          catch(ArrayIndexOutOfBoundsException e) { b2=true;}
          System.out.println("i1="+i1+" b2="+b2);
        }
      }
      algol% cat f1512104.java
      class f1512104 {
        static boolean b1= false;
        static boolean b2= false;
        static void check_array()
         {
           try{
             int i = (new int[1])[1]; // ArrayIndexOutofBoundsException
                                      // thrown
           }
           catch(ArrayIndexOutOfBoundsException e) { b1=true;}
           try {
             int i = (new int[0])[0]; // ArrayIndexOutofBoundsException
                                      // thrown
           }
           catch(ArrayIndexOutOfBoundsException e) { b2=true;}
         }
        public static void main(String[] arg)
         {
          check_array();
          System.out.println("b1="+b1);
          System.out.println("b2="+b2);
         }
      }

        Attachments

          Activity

            People

            Assignee:
            tturnidgsunw Todd Turnidge (Inactive)
            Reporter:
            ajacobssunw Allan Jacobs (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: