|
1 /* |
|
2 * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. |
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 * |
|
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 |
|
7 * published by the Free Software Foundation. |
|
8 * |
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
|
13 * accompanied this code). |
|
14 * |
|
15 * You should have received a copy of the GNU General Public License version |
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 * |
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 * or visit www.oracle.com if you need additional information or have any |
|
21 * questions. |
|
22 */ |
|
23 |
|
24 import java.beans.Introspector; |
|
25 import java.io.Serializable; |
|
26 import java.lang.reflect.Field; |
|
27 import java.lang.reflect.Method; |
|
28 import java.util.AbstractCollection; |
|
29 import java.util.AbstractList; |
|
30 import java.util.ArrayList; |
|
31 import java.util.Collection; |
|
32 import java.util.Comparator; |
|
33 import java.util.List; |
|
34 import java.util.RandomAccess; |
|
35 |
|
36 /** |
|
37 * @test |
|
38 * @bug 8211147 |
|
39 * @modules java.desktop/com.sun.beans.introspect:open |
|
40 */ |
|
41 public final class MethodOrderException { |
|
42 |
|
43 public static void main(final String[] args) throws Exception { |
|
44 // Public API, fails rarely |
|
45 testPublicAPI(); |
|
46 // Test using internal API, fails always |
|
47 testPrivateAPI(); |
|
48 } |
|
49 |
|
50 private static void testPublicAPI() throws Exception { |
|
51 Introspector.getBeanInfo(X.class); |
|
52 } |
|
53 |
|
54 private static void testPrivateAPI() throws Exception { |
|
55 Class<?> name = Class.forName( |
|
56 "com.sun.beans.introspect.MethodInfo$MethodOrder"); |
|
57 Field instance = name.getDeclaredField("instance"); |
|
58 instance.setAccessible(true); |
|
59 Comparator<Method> o = (Comparator) instance.get(name); |
|
60 List<Method> methods = List.of(X.class.getDeclaredMethods()); |
|
61 methods.forEach(m1 -> { |
|
62 methods.forEach(m2 -> { |
|
63 if (o.compare(m1, m2) != -o.compare(m2, m1)) { |
|
64 System.err.println("Method1 = "+ m1); |
|
65 System.err.println("Method2 = "+ m2); |
|
66 throw new RuntimeException("Broken contract!"); |
|
67 } |
|
68 }); |
|
69 }); |
|
70 } |
|
71 |
|
72 interface X_1 { |
|
73 |
|
74 AbstractList x_8(); |
|
75 } |
|
76 interface X_2 { |
|
77 |
|
78 Cloneable x_0(); |
|
79 } |
|
80 interface X_3 { |
|
81 |
|
82 Serializable x_1(); |
|
83 } |
|
84 interface X_4 { |
|
85 |
|
86 Object x_7(); |
|
87 } |
|
88 interface X_5 { |
|
89 |
|
90 RandomAccess x_6(); |
|
91 } |
|
92 interface X_6 { |
|
93 |
|
94 RandomAccess x_0(); |
|
95 } |
|
96 interface X_7 { |
|
97 |
|
98 Serializable x_5(); |
|
99 } |
|
100 interface X_8 { |
|
101 |
|
102 Object x_4(); |
|
103 } |
|
104 interface X_9 { |
|
105 |
|
106 RandomAccess x_5(); |
|
107 } |
|
108 interface X_10 { |
|
109 |
|
110 Cloneable x_5(); |
|
111 } |
|
112 interface X_11 { |
|
113 |
|
114 RandomAccess x_9(); |
|
115 } |
|
116 interface X_12 { |
|
117 |
|
118 Cloneable x_9(); |
|
119 } |
|
120 interface X_13 { |
|
121 |
|
122 Iterable x_2(); |
|
123 } |
|
124 interface X_14 { |
|
125 |
|
126 Collection x_7(); |
|
127 } |
|
128 interface X_15 { |
|
129 |
|
130 Serializable x_4(); |
|
131 } |
|
132 interface X_16 { |
|
133 |
|
134 Cloneable x_7(); |
|
135 } |
|
136 interface X_17 { |
|
137 |
|
138 Object x_1(); |
|
139 } |
|
140 interface X_18 { |
|
141 |
|
142 ArrayList x_6(); |
|
143 } |
|
144 interface X_19 { |
|
145 |
|
146 List x_5(); |
|
147 } |
|
148 interface X_20 { |
|
149 |
|
150 Collection x_2(); |
|
151 } |
|
152 interface X_21 { |
|
153 |
|
154 List x_1(); |
|
155 } |
|
156 interface X_22 { |
|
157 |
|
158 List x_3(); |
|
159 } |
|
160 interface X_23 { |
|
161 |
|
162 RandomAccess x_3(); |
|
163 } |
|
164 interface X_24 { |
|
165 |
|
166 RandomAccess x_1(); |
|
167 } |
|
168 interface X_25 { |
|
169 |
|
170 Object x_6(); |
|
171 } |
|
172 interface X_26 { |
|
173 |
|
174 Cloneable x_7(); |
|
175 } |
|
176 interface X_27 { |
|
177 |
|
178 Iterable x_0(); |
|
179 } |
|
180 interface X_28 { |
|
181 |
|
182 Iterable x_1(); |
|
183 } |
|
184 interface X_29 { |
|
185 |
|
186 AbstractList x_7(); |
|
187 } |
|
188 interface X_30 { |
|
189 |
|
190 AbstractList x_1(); |
|
191 } |
|
192 interface X_31 { |
|
193 |
|
194 Cloneable x_9(); |
|
195 } |
|
196 interface X_32 { |
|
197 |
|
198 ArrayList x_6(); |
|
199 } |
|
200 interface X_33 { |
|
201 |
|
202 Cloneable x_2(); |
|
203 } |
|
204 interface X_34 { |
|
205 |
|
206 Iterable x_6(); |
|
207 } |
|
208 interface X_35 { |
|
209 |
|
210 Iterable x_9(); |
|
211 } |
|
212 interface X_36 { |
|
213 |
|
214 AbstractList x_9(); |
|
215 } |
|
216 interface X_37 { |
|
217 |
|
218 Iterable x_7(); |
|
219 } |
|
220 interface X_38 { |
|
221 |
|
222 Iterable x_3(); |
|
223 } |
|
224 interface X_39 { |
|
225 |
|
226 Iterable x_9(); |
|
227 } |
|
228 interface X_40 { |
|
229 |
|
230 AbstractList x_3(); |
|
231 } |
|
232 interface X_41 { |
|
233 |
|
234 List x_0(); |
|
235 } |
|
236 interface X_42 { |
|
237 |
|
238 Iterable x_0(); |
|
239 } |
|
240 interface X_43 { |
|
241 |
|
242 Iterable x_2(); |
|
243 } |
|
244 interface X_44 { |
|
245 |
|
246 ArrayList x_4(); |
|
247 } |
|
248 interface X_45 { |
|
249 |
|
250 AbstractList x_4(); |
|
251 } |
|
252 interface X_46 { |
|
253 |
|
254 Collection x_4(); |
|
255 } |
|
256 interface X_47 { |
|
257 |
|
258 ArrayList x_2(); |
|
259 } |
|
260 interface X_48 { |
|
261 |
|
262 ArrayList x_6(); |
|
263 } |
|
264 interface X_49 { |
|
265 |
|
266 Serializable x_1(); |
|
267 } |
|
268 interface X_50 { |
|
269 |
|
270 Cloneable x_7(); |
|
271 } |
|
272 interface X_51 { |
|
273 |
|
274 Collection x_5(); |
|
275 } |
|
276 interface X_52 { |
|
277 |
|
278 RandomAccess x_5(); |
|
279 } |
|
280 interface X_53 { |
|
281 |
|
282 Collection x_5(); |
|
283 } |
|
284 interface X_54 { |
|
285 |
|
286 RandomAccess x_4(); |
|
287 } |
|
288 interface X_55 { |
|
289 |
|
290 Collection x_0(); |
|
291 } |
|
292 interface X_56 { |
|
293 |
|
294 Collection x_7(); |
|
295 } |
|
296 interface X_57 { |
|
297 |
|
298 Iterable x_9(); |
|
299 } |
|
300 interface X_58 { |
|
301 |
|
302 List x_3(); |
|
303 } |
|
304 interface X_59 { |
|
305 |
|
306 Serializable x_7(); |
|
307 } |
|
308 interface X_60 { |
|
309 |
|
310 AbstractCollection x_6(); |
|
311 } |
|
312 interface X_61 { |
|
313 |
|
314 AbstractList x_9(); |
|
315 } |
|
316 interface X_62 { |
|
317 |
|
318 List x_7(); |
|
319 } |
|
320 interface X_63 { |
|
321 |
|
322 AbstractCollection x_3(); |
|
323 } |
|
324 interface X_64 { |
|
325 |
|
326 RandomAccess x_4(); |
|
327 } |
|
328 interface X_65 { |
|
329 |
|
330 Object x_3(); |
|
331 } |
|
332 interface X_66 { |
|
333 |
|
334 RandomAccess x_6(); |
|
335 } |
|
336 interface X_67 { |
|
337 |
|
338 Cloneable x_6(); |
|
339 } |
|
340 interface X_68 { |
|
341 |
|
342 Cloneable x_3(); |
|
343 } |
|
344 interface X_69 { |
|
345 |
|
346 Collection x_5(); |
|
347 } |
|
348 interface X_70 { |
|
349 |
|
350 AbstractCollection x_0(); |
|
351 } |
|
352 interface X_71 { |
|
353 |
|
354 Object x_8(); |
|
355 } |
|
356 interface X_72 { |
|
357 |
|
358 AbstractCollection x_3(); |
|
359 } |
|
360 interface X_73 { |
|
361 |
|
362 Serializable x_4(); |
|
363 } |
|
364 interface X_74 { |
|
365 |
|
366 AbstractList x_8(); |
|
367 } |
|
368 interface X_75 { |
|
369 |
|
370 ArrayList x_1(); |
|
371 } |
|
372 interface X_76 { |
|
373 |
|
374 List x_5(); |
|
375 } |
|
376 interface X_77 { |
|
377 |
|
378 Object x_0(); |
|
379 } |
|
380 interface X_78 { |
|
381 |
|
382 Collection x_0(); |
|
383 } |
|
384 interface X_79 { |
|
385 |
|
386 ArrayList x_2(); |
|
387 } |
|
388 interface X_80 { |
|
389 |
|
390 ArrayList x_8(); |
|
391 } |
|
392 interface X_81 { |
|
393 |
|
394 Cloneable x_3(); |
|
395 } |
|
396 interface X_82 { |
|
397 |
|
398 Serializable x_1(); |
|
399 } |
|
400 interface X_83 { |
|
401 |
|
402 List x_1(); |
|
403 } |
|
404 interface X_84 { |
|
405 |
|
406 Collection x_5(); |
|
407 } |
|
408 interface X_85 { |
|
409 |
|
410 RandomAccess x_9(); |
|
411 } |
|
412 interface X_86 { |
|
413 |
|
414 AbstractList x_3(); |
|
415 } |
|
416 interface X_87 { |
|
417 |
|
418 Cloneable x_6(); |
|
419 } |
|
420 interface X_88 { |
|
421 |
|
422 Object x_2(); |
|
423 } |
|
424 interface X_89 { |
|
425 |
|
426 ArrayList x_5(); |
|
427 } |
|
428 interface X_90 { |
|
429 |
|
430 Iterable x_1(); |
|
431 } |
|
432 interface X_91 { |
|
433 |
|
434 ArrayList x_4(); |
|
435 } |
|
436 interface X_92 { |
|
437 |
|
438 Iterable x_6(); |
|
439 } |
|
440 interface X_93 { |
|
441 |
|
442 Collection x_7(); |
|
443 } |
|
444 interface X_94 { |
|
445 |
|
446 Iterable x_2(); |
|
447 } |
|
448 interface X_95 { |
|
449 |
|
450 AbstractList x_7(); |
|
451 } |
|
452 interface X_96 { |
|
453 |
|
454 RandomAccess x_2(); |
|
455 } |
|
456 interface X_97 { |
|
457 |
|
458 RandomAccess x_2(); |
|
459 } |
|
460 interface X_98 { |
|
461 |
|
462 List x_6(); |
|
463 } |
|
464 interface X_99 { |
|
465 |
|
466 Object x_4(); |
|
467 } |
|
468 interface X_100 { |
|
469 |
|
470 Collection x_7(); |
|
471 } |
|
472 static class X |
|
473 implements X_1, X_2, X_3, X_4, X_5, X_6, X_7, X_8, X_9, X_10, X_11, |
|
474 X_12, X_13, X_14, X_15, X_16, X_17, X_18, X_19, X_20, |
|
475 X_21, X_22, X_23, X_24, X_25, X_26, X_27, X_28, X_29, |
|
476 X_30, X_31, X_32, X_33, X_34, X_35, X_36, X_37, X_38, |
|
477 X_39, X_40, X_41, X_42, X_43, X_44, X_45, X_46, X_47, |
|
478 X_48, X_49, X_50, X_51, X_52, X_53, X_54, X_55, X_56, |
|
479 X_57, X_58, X_59, X_60, X_61, X_62, X_63, X_64, X_65, |
|
480 X_66, X_67, X_68, X_69, X_70, X_71, X_72, X_73, X_74, |
|
481 X_75, X_76, X_77, X_78, X_79, X_80, X_81, X_82, X_83, |
|
482 X_84, X_85, X_86, X_87, X_88, X_89, X_90, X_91, X_92, |
|
483 X_93, X_94, X_95, X_96, X_97, X_98, X_99, X_100 { |
|
484 |
|
485 public ArrayList x_0() { |
|
486 return null; |
|
487 } |
|
488 |
|
489 public ArrayList x_1() { |
|
490 return null; |
|
491 } |
|
492 |
|
493 public ArrayList x_2() { |
|
494 return null; |
|
495 } |
|
496 |
|
497 public ArrayList x_3() { |
|
498 return null; |
|
499 } |
|
500 |
|
501 public ArrayList x_4() { |
|
502 return null; |
|
503 } |
|
504 |
|
505 public ArrayList x_5() { |
|
506 return null; |
|
507 } |
|
508 |
|
509 public ArrayList x_6() { |
|
510 return null; |
|
511 } |
|
512 |
|
513 public ArrayList x_7() { |
|
514 return null; |
|
515 } |
|
516 |
|
517 public ArrayList x_8() { |
|
518 return null; |
|
519 } |
|
520 |
|
521 public ArrayList x_9() { |
|
522 return null; |
|
523 } |
|
524 } |
|
525 } |