Path: blob/master/test/jdk/java/beans/Introspector/Test6723447.java
41149 views
/*1* Copyright (c) 2009, 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*/2223/*24* @test25* @bug 672344726* @summary Tests return type for property setters27* @author Sergey Malenkov28*/2930import java.beans.IndexedPropertyDescriptor;31import java.beans.IntrospectionException;32import java.beans.Introspector;33import java.beans.PropertyDescriptor;34import java.lang.reflect.Method;35import java.math.BigDecimal;3637public class Test6723447 {3839public static void main(String[] args) {40test(Test6723447.class);41test(BigDecimal.class);42}4344private static void test(Class<?> type) {45for (PropertyDescriptor pd : getPropertyDescriptors(type)) {46test(pd.getWriteMethod());47if (pd instanceof IndexedPropertyDescriptor) {48IndexedPropertyDescriptor ipd = (IndexedPropertyDescriptor) pd;49test(ipd.getIndexedWriteMethod());50}51}52}5354private static void test(Method method) {55if (method != null) {56Class<?> type = method.getReturnType();57if (!type.equals(void.class)) {58throw new Error("unexpected return type: " + type);59}60}61}6263private static PropertyDescriptor[] getPropertyDescriptors(Class<?> type) {64try {65return Introspector.getBeanInfo(type).getPropertyDescriptors();66}67catch (IntrospectionException exception) {68throw new Error("unexpected exception", exception);69}70}7172public Object getValue() {73return null;74}7576public Object setValue(Object value) {77return value;78}7980public Object getValues(int index) {81return null;82}8384public Object setValues(int index, Object value) {85return value;86}87}888990