Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/beans/Introspector/Test8034164.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.beans.IndexedPropertyDescriptor;24import java.beans.PropertyDescriptor;2526/*27* @test28* @bug 803416429* @summary Tests that Introspector does not ignore indexed getter and setter for correct types30* @author Sergey Malenkov31*/3233public class Test8034164 {34public static final StringBuilder ERROR = new StringBuilder();3536public static void main(String[] args) {37test(Bean0000.class, false, false, false, false);38test(Bean0001.class, false, false, false, true);39test(Bean0010.class, false, false, true, false);40test(Bean0011.class, false, false, true, true);41test(Bean0100.class, false, true, false, false);42test(Bean0101.class, false, true, false, true);43test(Bean0110.class, false, true, true, false);44test(Bean0111.class, false, true, true, true);45test(Bean1000.class, true, false, false, false);46test(Bean1001.class, true, false, false, true);47test(Bean1010.class, true, false, true, false);48test(Bean1011.class, true, false, true, true);49test(Bean1100.class, true, true, false, false);50test(Bean1101.class, true, true, false, true);51test(Bean1110.class, true, true, true, false);52test(Bean1111.class, true, true, true, true);5354if (0 < ERROR.length()) {55throw new Error(ERROR.toString());56}57}5859private static void test(Class<?> type, boolean read, boolean write, boolean readIndexed, boolean writeIndexed) {60PropertyDescriptor pd = BeanUtils.findPropertyDescriptor(type, "size");61if (pd != null) {62test(type, "read", read, null != pd.getReadMethod());63test(type, "write", write, null != pd.getWriteMethod());64if (pd instanceof IndexedPropertyDescriptor) {65IndexedPropertyDescriptor ipd = (IndexedPropertyDescriptor) pd;66test(type, "indexed read", readIndexed, null != ipd.getIndexedReadMethod());67test(type, "indexed write", writeIndexed, null != ipd.getIndexedWriteMethod());68} else if (readIndexed || writeIndexed) {69error(type, "indexed property does not exist");70}71} else if (read || write || readIndexed || writeIndexed) {72error(type, "property does not exist");73}74}7576private static void test(Class<?> type, String name, boolean expected, boolean actual) {77if (expected && !actual) {78error(type, name + " method does not exist");79} else if (!expected && actual) {80error(type, name + " method is not expected");81}82}8384private static void error(Class<?> type, String message) {85ERROR.append("\n\t\t").append(type.getSimpleName()).append(".size: ").append(message);86}8788public static class Bean0000 {89}9091public static class Bean0001 {92public void setSize(int index, int value) {93}94}9596public static class Bean0010 {97public int getSize(int index) {98return 0;99}100}101102public static class Bean0011 {103public int getSize(int index) {104return 0;105}106107public void setSize(int index, int value) {108}109}110111public static class Bean0100 {112public void setSize(int[] value) {113}114}115116public static class Bean0101 {117public void setSize(int[] value) {118}119120public void setSize(int index, int value) {121}122}123124public static class Bean0110 {125public void setSize(int[] value) {126}127128public int getSize(int index) {129return 0;130}131}132133public static class Bean0111 {134public void setSize(int[] value) {135}136137public int getSize(int index) {138return 0;139}140141public void setSize(int index, int value) {142}143}144145public static class Bean1000 {146public int[] getSize() {147return null;148}149}150151public static class Bean1001 {152public int[] getSize() {153return null;154}155156public void setSize(int index, int value) {157}158}159160public static class Bean1010 {161public int[] getSize() {162return null;163}164165public int getSize(int index) {166return 0;167}168}169170public static class Bean1011 {171public int[] getSize() {172return null;173}174175public int getSize(int index) {176return 0;177}178179public void setSize(int index, int value) {180}181}182183public static class Bean1100 {184public int[] getSize() {185return null;186}187188public void setSize(int[] value) {189}190}191192public static class Bean1101 {193public int[] getSize() {194return null;195}196197public void setSize(int[] value) {198}199200public void setSize(int index, int value) {201}202}203204public static class Bean1110 {205public int[] getSize() {206return null;207}208209public void setSize(int[] value) {210}211212public int getSize(int index) {213return 0;214}215}216217public static class Bean1111 {218public int[] getSize() {219return null;220}221222public void setSize(int[] value) {223}224225public int getSize(int index) {226return 0;227}228229public void setSize(int index, int value) {230}231}232}233234235