Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/beans/Introspector/Test8034085.java
47964 views
/*1* Copyright (c) 2014, 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.awt.Window;24import java.beans.IndexedPropertyDescriptor;25import java.beans.PropertyDescriptor;2627/*28* @test29* @bug 803408530* @summary Tests that Introspector ignores indexed getter and setter for incorrect types31* @author Sergey Malenkov32*/3334public class Test8034085 {35public static final StringBuilder ERROR = new StringBuilder();3637public static void main(String[] args) {38test(Window.class, false, true, false, false);3940test(Bean0000.class, false, false, false, false);41test(Bean0001.class, false, false, false, true);42test(Bean0010.class, false, false, true, false);43test(Bean0011.class, false, false, true, true);44test(Bean0100.class, false, true, false, false);45test(Bean0101.class, false, true, false, false);46test(Bean0110.class, false, true, false, false);47test(Bean0111.class, false, true, false, false);48test(Bean1000.class, true, false, false, false);49test(Bean1001.class, true, false, false, false);50test(Bean1010.class, true, false, false, false);51test(Bean1011.class, true, false, false, false);52test(Bean1100.class, true, true, false, false);53test(Bean1101.class, true, true, false, false);54test(Bean1110.class, true, true, false, false);55test(Bean1111.class, true, true, false, false);5657if (0 < ERROR.length()) {58throw new Error(ERROR.toString());59}60}6162private static void test(Class<?> type, boolean read, boolean write, boolean readIndexed, boolean writeIndexed) {63PropertyDescriptor pd = BeanUtils.findPropertyDescriptor(type, "size");64if (pd != null) {65test(type, "read", read, null != pd.getReadMethod());66test(type, "write", write, null != pd.getWriteMethod());67if (pd instanceof IndexedPropertyDescriptor) {68IndexedPropertyDescriptor ipd = (IndexedPropertyDescriptor) pd;69test(type, "indexed read", readIndexed, null != ipd.getIndexedReadMethod());70test(type, "indexed write", writeIndexed, null != ipd.getIndexedWriteMethod());71} else if (readIndexed || writeIndexed) {72error(type, "indexed property does not exist");73}74} else if (read || write || readIndexed || writeIndexed) {75error(type, "property does not exist");76}77}7879private static void test(Class<?> type, String name, boolean expected, boolean actual) {80if (expected && !actual) {81error(type, name + " method does not exist");82} else if (!expected && actual) {83error(type, name + " method is not expected");84}85}8687private static void error(Class<?> type, String message) {88ERROR.append("\n\t\t").append(type.getSimpleName()).append(".size: ").append(message);89}9091public static class Bean0000 {92}9394public static class Bean0001 {95public void setSize(int index, int value) {96}97}9899public static class Bean0010 {100public int getSize(int index) {101return 0;102}103}104105public static class Bean0011 {106public int getSize(int index) {107return 0;108}109110public void setSize(int index, int value) {111}112}113114public static class Bean0100 {115public void setSize(int value) {116}117}118119public static class Bean0101 {120public void setSize(int value) {121}122123public void setSize(int index, int value) {124}125}126127public static class Bean0110 {128public void setSize(int value) {129}130131public int getSize(int index) {132return 0;133}134}135136public static class Bean0111 {137public void setSize(int value) {138}139140public int getSize(int index) {141return 0;142}143144public void setSize(int index, int value) {145}146}147148public static class Bean1000 {149public int getSize() {150return 0;151}152}153154public static class Bean1001 {155public int getSize() {156return 0;157}158159public void setSize(int index, int value) {160}161}162163public static class Bean1010 {164public int getSize() {165return 0;166}167168public int getSize(int index) {169return 0;170}171}172173public static class Bean1011 {174public int getSize() {175return 0;176}177178public int getSize(int index) {179return 0;180}181182public void setSize(int index, int value) {183}184}185186public static class Bean1100 {187public int getSize() {188return 0;189}190191public void setSize(int value) {192}193}194195public static class Bean1101 {196public int getSize() {197return 0;198}199200public void setSize(int value) {201}202203public void setSize(int index, int value) {204}205}206207public static class Bean1110 {208public int getSize() {209return 0;210}211212public void setSize(int value) {213}214215public int getSize(int index) {216return 0;217}218}219220public static class Bean1111 {221public int getSize() {222return 0;223}224225public void setSize(int value) {226}227228public int getSize(int index) {229return 0;230}231232public void setSize(int index, int value) {233}234}235}236237238