1 public class ArrayStore 2 { main(String[] args)3 public static void main(String[] args) 4 { 5 ArrayStore s = new ArrayStore(); 6 7 /* Check that bounds check takes precedence over array store check. */ 8 try 9 { 10 s.a(new String[1]); 11 } 12 catch (Exception x) 13 { 14 System.out.println (x.getClass().getName()); 15 } 16 17 try 18 { 19 s.a(new String[2]); 20 } 21 catch (Exception x) 22 { 23 System.out.println (x.getClass().getName()); 24 } 25 26 /* Check that += operator on String[] element works and throws bounds 27 exception. */ 28 try 29 { 30 s.b(new String[1]); 31 } 32 catch (Exception x) 33 { 34 System.out.println (x.getClass().getName()); 35 } 36 37 String[] sb = new String[2]; 38 sb[1] = "foo"; 39 s.b(sb); 40 System.out.println (sb[1]); 41 } 42 a(Object[] oa)43 void a(Object[] oa) 44 { 45 oa[1] = new Integer(2); 46 } 47 b(String[] sa)48 void b(String[] sa) 49 { 50 sa[1] += "bar"; 51 } 52 } 53