Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/beans/Introspector/Test7172865.java
47964 views
/*1* Copyright (c) 2013, 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.IndexedPropertyDescriptor;24import java.beans.MethodDescriptor;25import java.beans.PropertyDescriptor;2627/*28* @test29* @bug 7172854 717286530* @summary Tests that cached methods are not lost31* @author Sergey Malenkov32*/3334public class Test7172865 {35public static void main(String[] args) throws Exception {36int errors = 0;3738MethodDescriptor md = new MethodDescriptor(Test7172865.class.getMethod("getGood"));3940errors += test(PropertyDescriptor.class, "good", true);41PropertyDescriptor pdGoodString = new PropertyDescriptor("good", Test7172865.class, "getGood", "setGood");42PropertyDescriptor pdGoodMethod = new PropertyDescriptor("good",43Test7172865.class.getMethod("getGood"),44Test7172865.class.getMethod("setGood", args.getClass()));4546errors += test(PropertyDescriptor.class, "bad", false);47PropertyDescriptor pdBadString = new PropertyDescriptor("bad", Test7172865.class, "getBad", null);48PropertyDescriptor pdBadMethod = new PropertyDescriptor("bad",49Test7172865.class.getMethod("getBad"),50Test7172865.class.getMethod("setBad", args.getClass()));5152errors += test(IndexedPropertyDescriptor.class, "good", true);53IndexedPropertyDescriptor ipdGoodString = new IndexedPropertyDescriptor("good", Test7172865.class, "getGood", "setGood", "getGood", "setGood");54IndexedPropertyDescriptor ipdGoodMethod = new IndexedPropertyDescriptor("good",55Test7172865.class.getMethod("getGood"),56Test7172865.class.getMethod("setGood", args.getClass()),57Test7172865.class.getMethod("getGood", Integer.TYPE),58Test7172865.class.getMethod("setGood", Integer.TYPE, String.class));5960errors += test(IndexedPropertyDescriptor.class, "bad", false);61IndexedPropertyDescriptor ipdBadString = new IndexedPropertyDescriptor("bad", Test7172865.class, "getBad", null, "getBad", null);62IndexedPropertyDescriptor ipdBadMethod = new IndexedPropertyDescriptor("bad",63Test7172865.class.getMethod("getBad"),64Test7172865.class.getMethod("setBad", args.getClass()),65Test7172865.class.getMethod("getBad", Integer.TYPE),66Test7172865.class.getMethod("setBad", Integer.TYPE, String.class));6768for (int i = 1; i <= 2; i++) {69System.out.println("STEP: " + i);70errors += test("md", null != md.getMethod());7172errors += test("pdGoodString", pdGoodString, true, true);73errors += test("pdGoodMethod", pdGoodMethod, true, true);7475errors += test("pdBadString", pdBadString, true, false);76errors += test("pdBadMethod", pdBadMethod, true, true);7778errors += test("ipdGoodString", ipdGoodString, true, true, true, true);79errors += test("ipdGoodMethod", ipdGoodMethod, true, true, true, true);8081errors += test("ipdBadString", ipdBadString, true, false, true, false);82errors += test("ipdBadMethod", ipdBadMethod, true, true, true, true);8384try {85int[] array = new int[1024];86while (true) {87array = new int[array.length << 1];88}89}90catch (OutOfMemoryError error) {91System.gc();92}93}94if (errors > 0) {95throw new Error("found " + errors + " errors");96}97}9899private static int test(Class<?> type, String property, boolean value) {100String message = type.getSimpleName() + "(" + property + ") ";101try {102type.getConstructor(String.class, Class.class).newInstance(property, Test7172865.class);103message += "passed";104}105catch (Exception exception) {106message += "failed";107value = !value;108}109if (value) {110message += " as expected";111}112System.out.println(message);113return value ? 0 : 1;114}115116private static int test(String message, boolean value) {117System.out.println(message + ": " + (value ? "passed" : "failed"));118return value ? 0 : 1;119}120121private static int test(String message, PropertyDescriptor pd, boolean rm, boolean wm) {122return test(message + ".Read", rm == (null != pd.getReadMethod()))123+ test(message + ".Write", wm == (null != pd.getWriteMethod()));124}125126private static int test(String message, IndexedPropertyDescriptor ipd, boolean rm, boolean wm, boolean irm, boolean iwm) {127return test(message, ipd, rm, wm)128+ test(message + ".IndexedRead", irm == (null != ipd.getIndexedReadMethod()))129+ test(message + ".IndexedWrite", iwm == (null != ipd.getIndexedWriteMethod()));130}131132public String[] getGood() {133return null;134}135136public String getGood(int index) {137return null;138}139140public void setGood(String[] good) {141}142143public void setGood(int index, String value) {144}145146public String[] getBad() {147return null;148}149150public String getBad(int index) {151return null;152}153154public Test7172865 setBad(String[] bad) {155return null;156}157158public Test7172865 setBad(int index, String value) {159return null;160}161}162163164