46 try {
47 System.arraycopy(from, 1, to, 3, 2);
48 Asserts.fail("Expected ArrayStoreException not thrown");
49 } catch (ArrayStoreException e) {
50 Asserts.assertEquals(e.getMessage(), message);
51 }
52 }
53
54 static native void doNativeArrayStore(Object[] src, Object dst, int index);
55
56 static void testNativeASMessages(Object[] array, Object elem, int index, String message)
57 throws Exception {
58 try {
59 doNativeArrayStore(array, elem, index);
60 Asserts.fail("Expected ArrayStoreException not thrown");
61 } catch (ArrayStoreException e) {
62 Asserts.assertEquals(e.getMessage(), message);
63 }
64 }
65
66 static native void doNativeArrayStore2(Object src, Object dst, int index);
67
68 static void testNativeASMessages2(Object array, Object elem, int index, String message)
69 throws Exception {
70 try {
71 doNativeArrayStore2(array, elem, index);
72 Asserts.fail("Expected ArrayStoreException not thrown");
73 } catch (ArrayIndexOutOfBoundsException e) {
74 Asserts.assertEquals(e.getMessage(), message);
75 }
76 }
77
78 public static void main(String[] args) throws Exception {
79 try {
80 boolean[] za1 = new boolean[3];
81 byte[] ba1 = new byte[3];
82 short[] sa1 = new short[3];
83 char[] ca1 = new char[3];
84 int[] ia1 = new int[3];
85 long[] la1 = new long[3];
86 float[] fa1 = new float[3];
87 double[] da1 = new double[3];
88 Object[] oa1 = new Object[3];
89
90 boolean[] za2 = new boolean[9];
91 byte[] ba2 = new byte[9];
92 short[] sa2 = new short[9];
93 char[] ca2 = new char[9];
94 int[] ia2 = new int[9];
95 long[] la2 = new long[9];
96 float[] fa2 = new float[9];
97 double[] da2 = new double[9];
175 "arraycopy: element type mismatch: can not cast one of the " +
176 "elements of java.lang.Object[] to the type of the destination " +
177 "array, java.util.Date");
178
179 // These should succeed.
180 doNativeArrayStore(Sa1, "This is a string", 0);
181 doNativeArrayStore(oa1, "This is a string", 2);
182
183 testNativeASMessages(Da1, "This is not a date", 0,
184 "type mismatch: can not store java.lang.String to java.util.Date[0]");
185 testNativeASMessages(Da1, "This is not a date", 2,
186 "type mismatch: can not store java.lang.String to java.util.Date[2]");
187 testNativeASMessages(oa3, "This is not a date", 2,
188 "type mismatch: can not store java.lang.String to java.lang.Object[2][]");
189 testNativeASMessages(oa4, "This is not a date", 1,
190 "type mismatch: can not store java.lang.String to java.lang.Object[1][][]");
191 testNativeASMessages(ia3, "This is not a date", 1,
192 "type mismatch: can not store java.lang.String to int[1][]");
193 testNativeASMessages(ia4, "This is not a date", 2,
194 "type mismatch: can not store java.lang.String to int[2][][]");
195
196 testNativeASMessages2("This is not an array", "This is not a date", 2, "2");
197
198 } catch (java.lang.RuntimeException e) {
199 throw e;
200 } catch (Exception e) {
201 e.printStackTrace();
202 Asserts.fail("Wrong exception thrown: " + e);
203 }
204 }
205 }
|
46 try {
47 System.arraycopy(from, 1, to, 3, 2);
48 Asserts.fail("Expected ArrayStoreException not thrown");
49 } catch (ArrayStoreException e) {
50 Asserts.assertEquals(e.getMessage(), message);
51 }
52 }
53
54 static native void doNativeArrayStore(Object[] src, Object dst, int index);
55
56 static void testNativeASMessages(Object[] array, Object elem, int index, String message)
57 throws Exception {
58 try {
59 doNativeArrayStore(array, elem, index);
60 Asserts.fail("Expected ArrayStoreException not thrown");
61 } catch (ArrayStoreException e) {
62 Asserts.assertEquals(e.getMessage(), message);
63 }
64 }
65
66 public static void main(String[] args) throws Exception {
67 try {
68 boolean[] za1 = new boolean[3];
69 byte[] ba1 = new byte[3];
70 short[] sa1 = new short[3];
71 char[] ca1 = new char[3];
72 int[] ia1 = new int[3];
73 long[] la1 = new long[3];
74 float[] fa1 = new float[3];
75 double[] da1 = new double[3];
76 Object[] oa1 = new Object[3];
77
78 boolean[] za2 = new boolean[9];
79 byte[] ba2 = new byte[9];
80 short[] sa2 = new short[9];
81 char[] ca2 = new char[9];
82 int[] ia2 = new int[9];
83 long[] la2 = new long[9];
84 float[] fa2 = new float[9];
85 double[] da2 = new double[9];
163 "arraycopy: element type mismatch: can not cast one of the " +
164 "elements of java.lang.Object[] to the type of the destination " +
165 "array, java.util.Date");
166
167 // These should succeed.
168 doNativeArrayStore(Sa1, "This is a string", 0);
169 doNativeArrayStore(oa1, "This is a string", 2);
170
171 testNativeASMessages(Da1, "This is not a date", 0,
172 "type mismatch: can not store java.lang.String to java.util.Date[0]");
173 testNativeASMessages(Da1, "This is not a date", 2,
174 "type mismatch: can not store java.lang.String to java.util.Date[2]");
175 testNativeASMessages(oa3, "This is not a date", 2,
176 "type mismatch: can not store java.lang.String to java.lang.Object[2][]");
177 testNativeASMessages(oa4, "This is not a date", 1,
178 "type mismatch: can not store java.lang.String to java.lang.Object[1][][]");
179 testNativeASMessages(ia3, "This is not a date", 1,
180 "type mismatch: can not store java.lang.String to int[1][]");
181 testNativeASMessages(ia4, "This is not a date", 2,
182 "type mismatch: can not store java.lang.String to int[2][][]");
183
184 } catch (java.lang.RuntimeException e) {
185 throw e;
186 } catch (Exception e) {
187 e.printStackTrace();
188 Asserts.fail("Wrong exception thrown: " + e);
189 }
190 }
191 }
|