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

correct code throws an exception

XMLWordPrintable

    • generic
    • generic

      A DESCRIPTION OF THE PROBLEM :
      correct code throws an exception

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      run code

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      assigned value 2, to array's element at index 3
      ACTUAL -
      Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 3 out of bounds for length 1
      at org.unirail.Main.main(Main.java:13)

      ---------- BEGIN SOURCE ----------
      public class Main {
          
          static int[] array = new int[1];
          
          static int boo() {
              array = new int[10];
              return 3;
          }
          
          public static void main( String[] args ) {
              array[boo()] = 2;
          }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      public class Main {

      static int[] array = new int[1];

      static int boo() {
      array = new int[10];
      return 3;
      }

      public static void main( String[] args ) {
      int i = boo();
      array[i] = 2;
      }
      }

      FREQUENCY : always


            sswsharm swati sharma (Inactive)
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: