1 /*
   2  * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
   3  * Copyright (c) 2018 SAP SE. All rights reserved.
   4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   5  *
   6  * This code is free software; you can redistribute it and/or modify it
   7  * under the terms of the GNU General Public License version 2 only, as
   8  * published by the Free Software Foundation.
   9  *
  10  * This code is distributed in the hope that it will be useful, but WITHOUT
  11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  13  * version 2 for more details (a copy is included in the LICENSE file that
  14  * accompanied this code).
  15  *
  16  * You should have received a copy of the GNU General Public License version
  17  * 2 along with this work; if not, write to the Free Software Foundation,
  18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  19  *
  20  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  21  * or visit www.oracle.com if you need additional information or have any
  22  * questions.
  23  */
  24 
  25 /**
  26  * @test
  27  * @summary Test extended ArrayIndexOutOfBoundsException message for
  28  *   class files generated without debug information. The message lists
  29  *   information about the array and the indexes involved.
  30  * @compile ArrayIndexOutOfBoundsExceptionTest.java
  31  * @run testng ArrayIndexOutOfBoundsExceptionTest
  32  * @run testng/othervm -Xcomp -XX:-TieredCompilation  ArrayIndexOutOfBoundsExceptionTest
  33  * @run testng/othervm -Xcomp -XX:TieredStopAtLevel=1 ArrayIndexOutOfBoundsExceptionTest
  34  * @author Ann-Kathrin Wasle
  35  */
  36 
  37 import java.io.ByteArrayInputStream;
  38 import java.io.ByteArrayOutputStream;
  39 import java.io.ObjectInputStream;
  40 import java.io.ObjectOutputStream;
  41 import java.util.ArrayList;
  42 
  43 import org.testng.annotations.Test;
  44 
  45 import static org.testng.Assert.assertEquals;
  46 import static org.testng.Assert.assertNull;
  47 import static org.testng.Assert.assertNotNull;
  48 import static org.testng.Assert.assertTrue;
  49 import static org.testng.Assert.fail;
  50 
  51 /**
  52  * Tests the detailed messages for the ArrayIndexOutOfBoundsException.
  53  */
  54 public class ArrayIndexOutOfBoundsExceptionTest {
  55 
  56     // Some fields used in the test.
  57     static int[] staticArray = new int[0];
  58     static long[][] staticLongArray = new long[0][0];
  59     DoubleArrayGen dag;
  60     ArrayList<String> names = new ArrayList<>();
  61     ArrayList<String> curr;
  62 
  63     public static void main(String[] args) {
  64         ArrayIndexOutOfBoundsExceptionTest t = new ArrayIndexOutOfBoundsExceptionTest();
  65         try {
  66             t.testCreationViaNew();
  67             t.testCreationViaReflection();
  68             t.testCreationViaSerialization();
  69             t.testLoadedFromLocalVariable1();
  70             t.testLoadedFromLocalVariable2();
  71             t.testLoadedFromLocalVariable3();
  72             t.testLoadedFromLocalVariable4();
  73             t.testLoadedFromLocalVariable5();
  74             t.testLoadedFromLocalVariable6();
  75             t.testLoadedFromLocalVariable7();
  76             t.testLoadedFromLocalVariable8();
  77             t.testLoadedFromLocalVariable9();
  78             t.testLoadedFromLocalVariable10();
  79             t.testLoadedFromLocalVariable11();
  80             t.testLoadedFromMethod1();
  81             t.testLoadedFromMethod2();
  82             t.testLoadedFromMethod3();
  83             t.testLoadedFromMethod4();
  84             t.testLoadedFromStaticField1();
  85             t.testLoadedFromStaticField2();
  86             t.testLoadedFromStaticField3();
  87             t.testLoadedFromStaticField4();
  88             t.testWorkWithCompiler();
  89             t.testMissingLocalVariableTable();
  90             t.testAIOOBMessages();
  91         } catch (Exception e) {}
  92     }
  93 
  94     /**
  95      *
  96      */
  97     @Test
  98     public void testCreationViaNew() {
  99         assertNull(new ArrayIndexOutOfBoundsException().getMessage());
 100     }
 101 
 102     /**
 103      * @throws Exception
 104      */
 105     @Test
 106     public void testCreationViaReflection() throws Exception {
 107         Exception ex = ArrayIndexOutOfBoundsException.class.newInstance();
 108         assertNull(ex.getMessage());
 109     }
 110 
 111     /**
 112      * @throws Exception
 113      */
 114     @Test
 115     public void testCreationViaSerialization() throws Exception {
 116         Object o = new ArrayIndexOutOfBoundsException();
 117         ByteArrayOutputStream bos = new ByteArrayOutputStream();
 118         ObjectOutputStream oos = new ObjectOutputStream(bos);
 119         oos.writeObject(o);
 120         ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
 121         ObjectInputStream ois = new ObjectInputStream(bis);
 122         Exception ex = (Exception) ois.readObject();
 123         assertNull(ex.getMessage());
 124     }
 125 
 126     /**
 127      *
 128      */
 129     @Test
 130     public void testLoadedFromLocalVariable1() {
 131         Object[] a = new Object[5];
 132 
 133         try {
 134             a[10].hashCode();
 135             fail();
 136         } catch (ArrayIndexOutOfBoundsException e) {
 137             e.printStackTrace();
 138             assertNotNull(e.getMessage());
 139         }
 140     }
 141 
 142     /**
 143      *
 144      */
 145     @Test
 146     public void testLoadedFromLocalVariable2() {
 147         Object[] a = new Object[7];
 148 
 149         try {
 150             a[-7] = null;
 151             fail();
 152         } catch (ArrayIndexOutOfBoundsException e) {
 153             e.printStackTrace();
 154             assertNotNull(e.getMessage());
 155         }
 156     }
 157 
 158     /**
 159      *
 160      */
 161     @Test
 162     public void testLoadedFromLocalVariable3() {
 163         byte[] a = new byte[0];
 164 
 165         try {
 166             assertTrue(a[99] == 5);
 167             fail();
 168         } catch (ArrayIndexOutOfBoundsException e) {
 169             e.printStackTrace();
 170             assertNotNull(e.getMessage());
 171         }
 172     }
 173 
 174     /**
 175      *
 176      */
 177     @Test
 178     public void testLoadedFromLocalVariable4() {
 179         char[] a = new char[0];
 180 
 181         try {
 182             a[0] = 0;
 183             fail();
 184         } catch (ArrayIndexOutOfBoundsException e) {
 185             e.printStackTrace();
 186             assertNotNull(e.getMessage());
 187         }
 188     }
 189 
 190     /**
 191      *
 192      */
 193     @Test
 194     public void testLoadedFromLocalVariable5() {
 195         double[] a = new double[0];
 196 
 197         try {
 198             assertTrue(a[0] == 0);
 199             fail();
 200         } catch (ArrayIndexOutOfBoundsException e) {
 201             e.printStackTrace();
 202             assertNotNull(e.getMessage());
 203         }
 204     }
 205 
 206     /**
 207      *
 208      */
 209     @Test
 210     public void testLoadedFromLocalVariable6() {
 211         float[] a = new float[0];
 212 
 213         try {
 214             a[0] = 0;
 215             fail();
 216         } catch (ArrayIndexOutOfBoundsException e) {
 217             e.printStackTrace();
 218             assertNotNull(e.getMessage());
 219         }
 220     }
 221 
 222     /**
 223      *
 224      */
 225     @Test
 226     public void testLoadedFromLocalVariable7() {
 227         int[] a = new int[0];
 228 
 229         try {
 230             assertTrue(a[0] == 0);
 231             fail();
 232         } catch (ArrayIndexOutOfBoundsException e) {
 233             e.printStackTrace();
 234             assertNotNull(e.getMessage());
 235         }
 236     }
 237 
 238     /**
 239      *
 240      */
 241     @Test
 242     public void testLoadedFromLocalVariable8() {
 243         long[] a = new long[0];
 244 
 245         try {
 246             a[0] = 0;
 247             fail();
 248         } catch (ArrayIndexOutOfBoundsException e) {
 249             e.printStackTrace();
 250             assertNotNull(e.getMessage());
 251         }
 252     }
 253 
 254     /**
 255      *
 256      */
 257     @Test
 258     public void testLoadedFromLocalVariable9() {
 259         short[] a = new short[5];
 260 
 261         try {
 262             assertTrue(a[10] == 0);
 263             fail();
 264         } catch (ArrayIndexOutOfBoundsException e) {
 265             e.printStackTrace();
 266             assertNotNull(e.getMessage());
 267         }
 268     }
 269 
 270     /**
 271      *
 272      */
 273     @Test
 274     public void testLoadedFromLocalVariable10() {
 275         int[][][] a = new int[1][0][0];
 276 
 277         try {
 278             assertTrue(a[0][1][2] == 0);
 279             fail();
 280         } catch (ArrayIndexOutOfBoundsException e) {
 281             e.printStackTrace();
 282             assertNotNull(e.getMessage());
 283         }
 284     }
 285 
 286     /**
 287      *
 288      */
 289     @Test
 290     public void testLoadedFromLocalVariable11() {
 291         int[][][] a = new int[1][0][0];
 292 
 293         try {
 294             a[0][1][2] = 0;
 295             fail();
 296         } catch (ArrayIndexOutOfBoundsException e) {
 297             e.printStackTrace();
 298             assertNotNull(e.getMessage());
 299         }
 300     }
 301 
 302     /**
 303      *
 304      */
 305     @Test
 306     public void testLoadedFromMethod1() {
 307 
 308         try {
 309             assertTrue((ArrayGenerator.arrayReturner(false))[0] == null);
 310             fail();
 311         } catch (ArrayIndexOutOfBoundsException e) {
 312             e.printStackTrace();
 313             assertNotNull(e.getMessage());
 314         }
 315     }
 316 
 317     /**
 318      *
 319      */
 320     @Test
 321     public void testLoadedFromMethod2() {
 322         try {
 323             assertTrue(
 324                ((new ArrayGenerator().returnMyArray(1, 1, (short) 1)))[0] == null);
 325             fail();
 326         } catch (ArrayIndexOutOfBoundsException e) {
 327             e.printStackTrace();
 328             assertNotNull(e.getMessage());
 329         }
 330     }
 331 
 332     /**
 333      *
 334      */
 335     @Test
 336     public void testLoadedFromMethod3() {
 337         try {
 338             assertTrue((returnArray(null, null, 1f))[0] == null);
 339             fail();
 340         } catch (ArrayIndexOutOfBoundsException e) {
 341             e.printStackTrace();
 342             assertNotNull(e.getMessage());
 343         }
 344     }
 345 
 346     /**
 347      *
 348      */
 349     @Test
 350     public void testLoadedFromMethod4() {
 351         ImplTestLoadedFromMethod4(new DoubleArrayGenImpl());
 352     }
 353 
 354     /**
 355      * @param gen
 356      */
 357     public void ImplTestLoadedFromMethod4(DoubleArrayGen gen) {
 358         try {
 359             (gen.getArray())[0] = 1.0;
 360             fail();
 361         } catch (ArrayIndexOutOfBoundsException e) {
 362             e.printStackTrace();
 363             assertNotNull(e.getMessage());
 364         }
 365     }
 366 
 367     /**
 368      *
 369      */
 370     @Test
 371     public void testLoadedFromStaticField1() {
 372         try {
 373             assertTrue(staticArray[0] == 1);
 374             fail();
 375         } catch (ArrayIndexOutOfBoundsException e) {
 376             e.printStackTrace();
 377             assertNotNull(e.getMessage());
 378         }
 379     }
 380 
 381     /**
 382      *
 383      */
 384     @Test
 385     public void testLoadedFromStaticField2() {
 386         try {
 387             staticArray[0] = 2;
 388             fail();
 389         } catch (ArrayIndexOutOfBoundsException e) {
 390             e.printStackTrace();
 391             assertNotNull(e.getMessage());
 392         }
 393     }
 394 
 395     /**
 396      *
 397      */
 398     @Test
 399     public void testLoadedFromStaticField3() {
 400         try {
 401             assertTrue(staticLongArray[0][0] == 1L);
 402         } catch (ArrayIndexOutOfBoundsException e) {
 403             e.printStackTrace();
 404             assertNotNull(e.getMessage());
 405         }
 406     }
 407 
 408     /**
 409      *
 410      */
 411     @Test
 412     public void testLoadedFromStaticField4() {
 413         try {
 414             staticLongArray[0][0] = 2L;
 415             fail();
 416         } catch (ArrayIndexOutOfBoundsException e) {
 417             e.printStackTrace();
 418             assertNotNull(e.getMessage());
 419         }
 420     }
 421 
 422     /**
 423      *
 424      */
 425     @Test
 426     public void testWorkWithCompiler() {
 427         int[] a = {0, 1, 2};
 428         int i1 = 2;
 429         int i2 = 3;
 430 
 431         for (int i = 0; i < 10000000; i++) { // One 0 less is enough for d64.
 432             testImplWorkWithCompiler(a, i1);
 433         }
 434         testImplWorkWithCompiler(a, i2);
 435     }
 436 
 437     /**
 438      * @param a
 439      * @param i
 440      */
 441     public void testImplWorkWithCompiler(int[] a, int i) {
 442         try {
 443             assertTrue(a[i] == 2);
 444         } catch (ArrayIndexOutOfBoundsException e) {
 445             e.printStackTrace();
 446             assertNotNull(e.getMessage());
 447         }
 448     }
 449 
 450     private Object[] returnArray(String[][] dummy1, int[][][] dummy2, float dummy3) {
 451         return new Object[0];
 452     }
 453 
 454     /**
 455      *
 456      */
 457     public static interface DoubleArrayGen {
 458         /**
 459          * @return double Array
 460          */
 461         public double[] getArray();
 462     }
 463 
 464     /**
 465      *
 466      */
 467     public static class DoubleArrayGenImpl implements DoubleArrayGen {
 468         @Override
 469         public double[] getArray() {
 470             return new double[0];
 471         }
 472     }
 473 
 474     /**
 475      *
 476      */
 477     public static class ArrayGenerator {
 478 
 479         /**
 480          * @param dummy1
 481          * @return Object Array
 482          */
 483         public static Object[] arrayReturner(boolean dummy1) {
 484             return new Object[0];
 485         }
 486 
 487         /**
 488          * @param dummy1
 489          * @param dummy2
 490          * @param dummy3
 491          * @return Object Array
 492          */
 493         public Object[] returnMyArray(double dummy1, long dummy2, short dummy3) {
 494             return new Object[0];
 495         }
 496     }
 497 
 498 
 499     /**
 500      *
 501      */
 502     @Test
 503     public void testMissingLocalVariableTable() {
 504         doTestMissingLocalVariableTable(names);
 505 
 506         System.out.println("Names");
 507 
 508         for (int i = 0; i < names.size(); ++i) {
 509             System.out.println(names.get(i));
 510         }
 511 
 512         String[] expectedNames = new String[] {
 513                 "Index 0 out-of-bounds for length 0.",
 514                 "Index -1 out-of-bounds for length 10.",
 515                 "Index 1 out-of-bounds for length 0.",
 516                 "Index 7 out-of-bounds for length 5."
 517         };
 518 
 519         assertEquals(expectedNames.length, names.size());
 520 
 521         for (int i = 0; i < expectedNames.length; ++i) {
 522             assertEquals(names.get(i), expectedNames[i]);
 523         }
 524     }
 525 
 526     private void doTestMissingLocalVariableTable(ArrayList<String> names) {
 527         curr = names;
 528         doTestMissingLocalVariableTable1();
 529         doTestMissingLocalVariableTable2(new Object[10], new boolean[0], new double[5][1]);
 530     }
 531 
 532     private void doTestMissingLocalVariableTable1() {
 533         try {
 534             staticArray[0] = 0;
 535             fail();
 536         }
 537         catch (ArrayIndexOutOfBoundsException e) {
 538             curr.add(e.getMessage());
 539         }
 540     }
 541 
 542     private void doTestMissingLocalVariableTable2(Object[] o1, boolean z1[], double[][] dd1) {
 543         try {
 544             o1[-1].hashCode();
 545             fail();
 546         }
 547         catch (ArrayIndexOutOfBoundsException e) {
 548             curr.add(e.getMessage());
 549         }
 550 
 551         try {
 552             z1[1] = true;
 553             fail();
 554         }
 555         catch (ArrayIndexOutOfBoundsException e) {
 556             curr.add(e.getMessage());
 557         }
 558 
 559         try {
 560             assertTrue(dd1[7][1] == 0);
 561             fail();
 562         }
 563         catch (ArrayIndexOutOfBoundsException e) {
 564             curr.add(e.getMessage());
 565         }
 566     }
 567 
 568     /**
 569      *
 570      */
 571     @Test
 572     public void testAIOOBMessages() {
 573         boolean[] za1 = new boolean[0];
 574         byte[]    ba1 = new byte[0];
 575         short[]   sa1 = new short[0];
 576         char[]    ca1 = new char[0];
 577         int[]     ia1 = new int[0];
 578         long[]    la1 = new long[0];
 579         float[]   fa1 = new float[0];
 580         double[]  da1 = new double[0];
 581         Object[]  oa1 = new Object[10];
 582         Object[]  oa2 = new Object[5];
 583 
 584         boolean[] za2 = new boolean[10];
 585         boolean[] za3 = new boolean[5];
 586         byte[]    ba2 = new byte[10];
 587         byte[]    ba3 = new byte[5];
 588         short[]   sa2 = new short[10];
 589         short[]   sa3 = new short[5];
 590         char[]    ca2 = new char[10];
 591         char[]    ca3 = new char[5];
 592         int[]     ia2 = new int[10];
 593         int[]     ia3 = new int[5];
 594         long[]    la2 = new long[10];
 595         long[]    la3 = new long[5];
 596         float[]   fa2 = new float[10];
 597         float[]   fa3 = new float[5];
 598         double[]  da2 = new double[10];
 599         double[]  da3 = new double[5];
 600 
 601         try {
 602             System.out.println(za1[-5]);
 603             fail();
 604         }
 605         catch (ArrayIndexOutOfBoundsException e) {
 606             assertEquals(e.getMessage(),
 607                 "Index -5 out-of-bounds for length 0.");
 608         }
 609 
 610         try {
 611             System.out.println(ba1[0]);
 612             fail();
 613         }
 614         catch (ArrayIndexOutOfBoundsException e) {
 615             assertEquals(e.getMessage(),
 616                 "Index 0 out-of-bounds for length 0.");
 617         }
 618 
 619         try {
 620             System.out.println(sa1[0]);
 621             fail();
 622         }
 623         catch (ArrayIndexOutOfBoundsException e) {
 624             assertEquals(e.getMessage(),
 625                 "Index 0 out-of-bounds for length 0.");
 626         }
 627 
 628         try {
 629             System.out.println(ca1[0]);
 630             fail();
 631         }
 632         catch (ArrayIndexOutOfBoundsException e) {
 633             assertEquals(e.getMessage(),
 634                 "Index 0 out-of-bounds for length 0.");
 635         }
 636 
 637         try {
 638             System.out.println(ia1[0]);
 639             fail();
 640         }
 641         catch (ArrayIndexOutOfBoundsException e) {
 642             assertEquals(e.getMessage(),
 643                 "Index 0 out-of-bounds for length 0.");
 644         }
 645 
 646         try {
 647             System.out.println(la1[0]);
 648             fail();
 649         }
 650         catch (ArrayIndexOutOfBoundsException e) {
 651             assertEquals(e.getMessage(),
 652                 "Index 0 out-of-bounds for length 0.");
 653         }
 654 
 655         try {
 656             System.out.println(fa1[0]);
 657             fail();
 658         }
 659         catch (ArrayIndexOutOfBoundsException e) {
 660             assertEquals(e.getMessage(),
 661                 "Index 0 out-of-bounds for length 0.");
 662         }
 663 
 664         try {
 665             System.out.println(da1[0]);
 666             fail();
 667         }
 668         catch (ArrayIndexOutOfBoundsException e) {
 669             assertEquals(e.getMessage(),
 670                 "Index 0 out-of-bounds for length 0.");
 671         }
 672 
 673         try {
 674             System.out.println(oa1[12]);
 675             fail();
 676         }
 677         catch (ArrayIndexOutOfBoundsException e) {
 678             assertEquals(e.getMessage(),
 679                 "Index 12 out-of-bounds for length 10.");
 680         }
 681 
 682         try {
 683             System.out.println(za1[0] = false);
 684             fail();
 685         }
 686         catch (ArrayIndexOutOfBoundsException e) {
 687             assertEquals(e.getMessage(),
 688                 "Index 0 out-of-bounds for length 0.");
 689         }
 690 
 691         try {
 692             System.out.println(ba1[0] = 0);
 693             fail();
 694         }
 695         catch (ArrayIndexOutOfBoundsException e) {
 696             assertEquals(e.getMessage(),
 697                 "Index 0 out-of-bounds for length 0.");
 698         }
 699 
 700         try {
 701             System.out.println(sa1[0] = 0);
 702             fail();
 703         }
 704         catch (ArrayIndexOutOfBoundsException e) {
 705             assertEquals(e.getMessage(),
 706                 "Index 0 out-of-bounds for length 0.");
 707         }
 708 
 709         try {
 710             System.out.println(ca1[0] = 0);
 711             fail();
 712         }
 713         catch (ArrayIndexOutOfBoundsException e) {
 714             assertEquals(e.getMessage(),
 715                 "Index 0 out-of-bounds for length 0.");
 716         }
 717 
 718         try {
 719             System.out.println(ia1[0] = 0);
 720             fail();
 721         }
 722         catch (ArrayIndexOutOfBoundsException e) {
 723             assertEquals(e.getMessage(),
 724                 "Index 0 out-of-bounds for length 0.");
 725         }
 726 
 727         try {
 728             System.out.println(la1[0] = 0);
 729             fail();
 730         }
 731         catch (ArrayIndexOutOfBoundsException e) {
 732             assertEquals(e.getMessage(),
 733                 "Index 0 out-of-bounds for length 0.");
 734         }
 735 
 736         try {
 737             System.out.println(fa1[0] = 0);
 738             fail();
 739         }
 740         catch (ArrayIndexOutOfBoundsException e) {
 741             assertEquals(e.getMessage(),
 742                 "Index 0 out-of-bounds for length 0.");
 743         }
 744 
 745         try {
 746             System.out.println(da1[0] = 0);
 747             fail();
 748         }
 749         catch (ArrayIndexOutOfBoundsException e) {
 750             assertEquals(e.getMessage(),
 751                 "Index 0 out-of-bounds for length 0.");
 752         }
 753 
 754         try {
 755             System.out.println(oa1[-2] = null);
 756             fail();
 757         }
 758         catch (ArrayIndexOutOfBoundsException e) {
 759             assertEquals(e.getMessage(),
 760                 "Index -2 out-of-bounds for length 10.");
 761         }
 762 
 763         try {
 764             assertTrue((ArrayGenerator.arrayReturner(false))[0] == null);
 765             fail();
 766         } catch (ArrayIndexOutOfBoundsException e) {
 767             assertEquals(e.getMessage(),
 768                 "Index 0 out-of-bounds for length 0.");
 769         }
 770         try {
 771             staticArray[0] = 2;
 772             fail();
 773         } catch (ArrayIndexOutOfBoundsException e) {
 774             assertEquals(e.getMessage(),
 775                 "Index 0 out-of-bounds for length 0.");
 776         }
 777 
 778         // Test all five possible messages of arraycopy exceptions thrown in ObjArrayKlass::copy_array()
 779 
 780         try {
 781             System.arraycopy(oa1, -17, oa2, 0, 5);
 782             fail();
 783         } catch (ArrayIndexOutOfBoundsException e) {
 784             assertEquals(e.getMessage(),
 785                 "while trying to copy from index -17 of an object array with length 10");
 786         }
 787 
 788         try {
 789             System.arraycopy(oa1, 2, oa2, -18, 5);
 790             fail();
 791         } catch (ArrayIndexOutOfBoundsException e) {
 792             assertEquals(e.getMessage(),
 793                 "while trying to copy to index -18 of an object array with length 5");
 794         }
 795 
 796         try {
 797             System.arraycopy(oa1, 2, oa2, 0, -19);
 798             fail();
 799         } catch (ArrayIndexOutOfBoundsException e) {
 800             assertEquals(e.getMessage(),
 801                 "while trying to copy a negative range -19 from an object array with length 10 to an object array with length 5");
 802         }
 803 
 804         try {
 805             System.arraycopy(oa1, 8, oa2, 0, 5);
 806             fail();
 807         } catch (ArrayIndexOutOfBoundsException e) {
 808             assertEquals(e.getMessage(),
 809                 "while trying to copy from index 13 of an object array with length 10");
 810         }
 811 
 812         try {
 813             System.arraycopy(oa1, 1, oa2, 0, 7);
 814             fail();
 815         } catch (ArrayIndexOutOfBoundsException e) {
 816             assertEquals(e.getMessage(),
 817                 "while trying to copy to index 7 of an object array with length 5");
 818         }
 819 
 820         // Test all five possible messages of arraycopy exceptions thrown in TypeArrayKlass::copy_array()
 821 
 822         try {
 823             System.arraycopy(da2, -17, da3, 0, 5);
 824             fail();
 825         } catch (ArrayIndexOutOfBoundsException e) {
 826             assertEquals(e.getMessage(),
 827                 "while trying to copy from index -17 of a double array with length 10");
 828         }
 829 
 830         try {
 831             System.arraycopy(da2, 2, da3, -18, 5);
 832             fail();
 833         } catch (ArrayIndexOutOfBoundsException e) {
 834             assertEquals(e.getMessage(),
 835                 "while trying to copy to index -18 of a double array with length 5");
 836         }
 837 
 838         try {
 839             System.arraycopy(da2, 2, da3, 0, -19);
 840             fail();
 841         } catch (ArrayIndexOutOfBoundsException e) {
 842             assertEquals(e.getMessage(),
 843                 "while trying to copy a negative range -19 from a double array with length 10 to a double array with length 5");
 844         }
 845 
 846         try {
 847             System.arraycopy(da2, 8, da3, 0, 5);
 848             fail();
 849         } catch (ArrayIndexOutOfBoundsException e) {
 850             assertEquals(e.getMessage(),
 851                 "while trying to copy from index 13 of a double array with length 10");
 852         }
 853 
 854         try {
 855             System.arraycopy(da2, 1, da3, 0, 7);
 856             fail();
 857         } catch (ArrayIndexOutOfBoundsException e) {
 858             assertEquals(e.getMessage(),
 859                 "while trying to copy to index 7 of a double array with length 5");
 860         }
 861 
 862         // Test all possible basic types in the messages of arraycopy exceptions thrown in TypeArrayKlass::copy_array()
 863 
 864         try {
 865             System.arraycopy(za2, -17, za3, 0, 5);
 866             fail();
 867         } catch (ArrayIndexOutOfBoundsException e) {
 868             assertEquals(e.getMessage(),
 869                 "while trying to copy from index -17 of a boolean array with length 10");
 870         }
 871 
 872         try {
 873             System.arraycopy(ba2, 2, ba3, -18, 5);
 874             fail();
 875         } catch (ArrayIndexOutOfBoundsException e) {
 876             assertEquals(e.getMessage(),
 877                 "while trying to copy to index -18 of a byte array with length 5");
 878         }
 879 
 880         try {
 881             System.arraycopy(sa2, 2, sa3, 0, -19);
 882             fail();
 883         } catch (ArrayIndexOutOfBoundsException e) {
 884             assertEquals(e.getMessage(),
 885                 "while trying to copy a negative range -19 from a short array with length 10 to a short array with length 5");
 886         }
 887 
 888         try {
 889             System.arraycopy(ca2, 8, ca3, 0, 5);
 890             fail();
 891         } catch (ArrayIndexOutOfBoundsException e) {
 892             assertEquals(e.getMessage(),
 893                 "while trying to copy from index 13 of a char array with length 10");
 894         }
 895 
 896         try {
 897             System.arraycopy(ia2, 2, ia3, 0, -19);
 898             fail();
 899         } catch (ArrayIndexOutOfBoundsException e) {
 900             assertEquals(e.getMessage(),
 901                 "while trying to copy a negative range -19 from a int array with length 10 to a int array with length 5");
 902         }
 903 
 904         try {
 905             System.arraycopy(la2, 1, la3, 0, 7);
 906             fail();
 907         } catch (ArrayIndexOutOfBoundsException e) {
 908             assertEquals(e.getMessage(),
 909                 "while trying to copy to index 7 of a long array with length 5");
 910         }
 911 
 912         try {
 913             System.arraycopy(fa2, 1, fa3, 0, 7);
 914             fail();
 915         } catch (ArrayIndexOutOfBoundsException e) {
 916             assertEquals(e.getMessage(),
 917                 "while trying to copy to index 7 of a float array with length 5");
 918         }
 919     }
 920 }