equal
deleted
inserted
replaced
1 /* |
1 /* |
2 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. |
7 * published by the Free Software Foundation. |
52 } |
52 } |
53 |
53 |
54 public class LinkageErrors { |
54 public class LinkageErrors { |
55 final static MethodHandles.Lookup L = MethodHandles.lookup(); |
55 final static MethodHandles.Lookup L = MethodHandles.lookup(); |
56 |
56 |
57 static void test(MethodHandle mh) { |
57 static void testICCE(MethodHandle mh) { |
58 try { |
58 try { |
59 mh.invokeExact(); |
59 mh.invokeExact(); |
60 throw new AssertionError("No exception thrown"); |
60 throw new AssertionError("No exception thrown"); |
61 } catch (LinkageError e) { |
61 } catch (IncompatibleClassChangeError e) { |
|
62 return; // expected |
|
63 } catch (AssertionError e) { |
|
64 throw e; // rethrow |
|
65 } catch (Throwable e) { |
|
66 throw new AssertionError("Unexpected exception", e); |
|
67 } |
|
68 } |
|
69 |
|
70 static void testNSME(MethodHandle mh) { |
|
71 try { |
|
72 mh.invokeExact(); |
|
73 throw new AssertionError("No exception thrown"); |
|
74 } catch (NoSuchMethodError e) { |
62 return; // expected |
75 return; // expected |
63 } catch (AssertionError e) { |
76 } catch (AssertionError e) { |
64 throw e; // rethrow |
77 throw e; // rethrow |
65 } catch (Throwable e) { |
78 } catch (Throwable e) { |
66 throw new AssertionError("Unexpected exception", e); |
79 throw new AssertionError("Unexpected exception", e); |
91 MethodHandle testI3_null = testI3.bindTo(null); |
104 MethodHandle testI3_null = testI3.bindTo(null); |
92 MethodHandle testX3_X = testX3.bindTo(new X()); |
105 MethodHandle testX3_X = testX3.bindTo(new X()); |
93 MethodHandle testX3_null = testX3.bindTo(null); |
106 MethodHandle testX3_null = testX3.bindTo(null); |
94 |
107 |
95 for (int i = 0; i < 20_000; i++) { |
108 for (int i = 0; i < 20_000; i++) { |
96 test(testI1_A); |
109 testNSME(testI1_A); |
97 test(testI1_null); |
110 testNSME(testI1_null); |
98 test(testX1_X); |
111 testNSME(testX1_X); |
99 test(testX1_null); |
112 testNSME(testX1_null); |
100 |
113 |
101 test(testI2); |
114 testICCE(testI2); |
102 test(testX2); |
115 testICCE(testX2); |
103 |
116 |
104 test(testI3_A); |
117 testICCE(testI3_A); |
105 test(testI3_null); |
118 testICCE(testI3_null); |
106 test(testX3_X); |
119 testICCE(testX3_X); |
107 test(testX3_null); |
120 testICCE(testX3_null); |
108 } |
121 } |
109 |
122 |
110 System.out.println("TEST PASSED"); |
123 System.out.println("TEST PASSED"); |
111 } |
124 } |
112 } |
125 } |