Path: blob/master/test/jdk/java/beans/Introspector/MethodOrderException.java
41149 views
/*1* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223import java.beans.Introspector;24import java.io.Serializable;25import java.lang.reflect.Field;26import java.lang.reflect.Method;27import java.util.AbstractCollection;28import java.util.AbstractList;29import java.util.ArrayList;30import java.util.Collection;31import java.util.Comparator;32import java.util.List;33import java.util.RandomAccess;3435/**36* @test37* @bug 821114738* @modules java.desktop/com.sun.beans.introspect:open39*/40public final class MethodOrderException {4142public static void main(final String[] args) throws Exception {43// Public API, fails rarely44testPublicAPI();45// Test using internal API, fails always46testPrivateAPI();47}4849private static void testPublicAPI() throws Exception {50Introspector.getBeanInfo(X.class);51}5253private static void testPrivateAPI() throws Exception {54Class<?> name = Class.forName(55"com.sun.beans.introspect.MethodInfo$MethodOrder");56Field instance = name.getDeclaredField("instance");57instance.setAccessible(true);58Comparator<Method> o = (Comparator) instance.get(name);59List<Method> methods = List.of(X.class.getDeclaredMethods());60methods.forEach(m1 -> {61methods.forEach(m2 -> {62if (o.compare(m1, m2) != -o.compare(m2, m1)) {63System.err.println("Method1 = "+ m1);64System.err.println("Method2 = "+ m2);65throw new RuntimeException("Broken contract!");66}67});68});69}7071interface X_1 {7273AbstractList x_8();74}75interface X_2 {7677Cloneable x_0();78}79interface X_3 {8081Serializable x_1();82}83interface X_4 {8485Object x_7();86}87interface X_5 {8889RandomAccess x_6();90}91interface X_6 {9293RandomAccess x_0();94}95interface X_7 {9697Serializable x_5();98}99interface X_8 {100101Object x_4();102}103interface X_9 {104105RandomAccess x_5();106}107interface X_10 {108109Cloneable x_5();110}111interface X_11 {112113RandomAccess x_9();114}115interface X_12 {116117Cloneable x_9();118}119interface X_13 {120121Iterable x_2();122}123interface X_14 {124125Collection x_7();126}127interface X_15 {128129Serializable x_4();130}131interface X_16 {132133Cloneable x_7();134}135interface X_17 {136137Object x_1();138}139interface X_18 {140141ArrayList x_6();142}143interface X_19 {144145List x_5();146}147interface X_20 {148149Collection x_2();150}151interface X_21 {152153List x_1();154}155interface X_22 {156157List x_3();158}159interface X_23 {160161RandomAccess x_3();162}163interface X_24 {164165RandomAccess x_1();166}167interface X_25 {168169Object x_6();170}171interface X_26 {172173Cloneable x_7();174}175interface X_27 {176177Iterable x_0();178}179interface X_28 {180181Iterable x_1();182}183interface X_29 {184185AbstractList x_7();186}187interface X_30 {188189AbstractList x_1();190}191interface X_31 {192193Cloneable x_9();194}195interface X_32 {196197ArrayList x_6();198}199interface X_33 {200201Cloneable x_2();202}203interface X_34 {204205Iterable x_6();206}207interface X_35 {208209Iterable x_9();210}211interface X_36 {212213AbstractList x_9();214}215interface X_37 {216217Iterable x_7();218}219interface X_38 {220221Iterable x_3();222}223interface X_39 {224225Iterable x_9();226}227interface X_40 {228229AbstractList x_3();230}231interface X_41 {232233List x_0();234}235interface X_42 {236237Iterable x_0();238}239interface X_43 {240241Iterable x_2();242}243interface X_44 {244245ArrayList x_4();246}247interface X_45 {248249AbstractList x_4();250}251interface X_46 {252253Collection x_4();254}255interface X_47 {256257ArrayList x_2();258}259interface X_48 {260261ArrayList x_6();262}263interface X_49 {264265Serializable x_1();266}267interface X_50 {268269Cloneable x_7();270}271interface X_51 {272273Collection x_5();274}275interface X_52 {276277RandomAccess x_5();278}279interface X_53 {280281Collection x_5();282}283interface X_54 {284285RandomAccess x_4();286}287interface X_55 {288289Collection x_0();290}291interface X_56 {292293Collection x_7();294}295interface X_57 {296297Iterable x_9();298}299interface X_58 {300301List x_3();302}303interface X_59 {304305Serializable x_7();306}307interface X_60 {308309AbstractCollection x_6();310}311interface X_61 {312313AbstractList x_9();314}315interface X_62 {316317List x_7();318}319interface X_63 {320321AbstractCollection x_3();322}323interface X_64 {324325RandomAccess x_4();326}327interface X_65 {328329Object x_3();330}331interface X_66 {332333RandomAccess x_6();334}335interface X_67 {336337Cloneable x_6();338}339interface X_68 {340341Cloneable x_3();342}343interface X_69 {344345Collection x_5();346}347interface X_70 {348349AbstractCollection x_0();350}351interface X_71 {352353Object x_8();354}355interface X_72 {356357AbstractCollection x_3();358}359interface X_73 {360361Serializable x_4();362}363interface X_74 {364365AbstractList x_8();366}367interface X_75 {368369ArrayList x_1();370}371interface X_76 {372373List x_5();374}375interface X_77 {376377Object x_0();378}379interface X_78 {380381Collection x_0();382}383interface X_79 {384385ArrayList x_2();386}387interface X_80 {388389ArrayList x_8();390}391interface X_81 {392393Cloneable x_3();394}395interface X_82 {396397Serializable x_1();398}399interface X_83 {400401List x_1();402}403interface X_84 {404405Collection x_5();406}407interface X_85 {408409RandomAccess x_9();410}411interface X_86 {412413AbstractList x_3();414}415interface X_87 {416417Cloneable x_6();418}419interface X_88 {420421Object x_2();422}423interface X_89 {424425ArrayList x_5();426}427interface X_90 {428429Iterable x_1();430}431interface X_91 {432433ArrayList x_4();434}435interface X_92 {436437Iterable x_6();438}439interface X_93 {440441Collection x_7();442}443interface X_94 {444445Iterable x_2();446}447interface X_95 {448449AbstractList x_7();450}451interface X_96 {452453RandomAccess x_2();454}455interface X_97 {456457RandomAccess x_2();458}459interface X_98 {460461List x_6();462}463interface X_99 {464465Object x_4();466}467interface X_100 {468469Collection x_7();470}471static class X472implements X_1, X_2, X_3, X_4, X_5, X_6, X_7, X_8, X_9, X_10, X_11,473X_12, X_13, X_14, X_15, X_16, X_17, X_18, X_19, X_20,474X_21, X_22, X_23, X_24, X_25, X_26, X_27, X_28, X_29,475X_30, X_31, X_32, X_33, X_34, X_35, X_36, X_37, X_38,476X_39, X_40, X_41, X_42, X_43, X_44, X_45, X_46, X_47,477X_48, X_49, X_50, X_51, X_52, X_53, X_54, X_55, X_56,478X_57, X_58, X_59, X_60, X_61, X_62, X_63, X_64, X_65,479X_66, X_67, X_68, X_69, X_70, X_71, X_72, X_73, X_74,480X_75, X_76, X_77, X_78, X_79, X_80, X_81, X_82, X_83,481X_84, X_85, X_86, X_87, X_88, X_89, X_90, X_91, X_92,482X_93, X_94, X_95, X_96, X_97, X_98, X_99, X_100 {483484public ArrayList x_0() {485return null;486}487488public ArrayList x_1() {489return null;490}491492public ArrayList x_2() {493return null;494}495496public ArrayList x_3() {497return null;498}499500public ArrayList x_4() {501return null;502}503504public ArrayList x_5() {505return null;506}507508public ArrayList x_6() {509return null;510}511512public ArrayList x_7() {513return null;514}515516public ArrayList x_8() {517return null;518}519520public ArrayList x_9() {521return null;522}523}524}525526527