1 /* 2 * Copyright (c) 2003, 2007, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /* 25 * @test 26 * @bug 4168833 27 * @summary Tests that Introspector does not create IndexedPropertyDescriptor 28 * from non-indexed PropertyDescriptor 29 * @author Mark Davidson 30 */ 31 32 import java.awt.Color; 33 import java.awt.Dimension; 34 35 import java.beans.IndexedPropertyDescriptor; 36 import java.beans.PropertyDescriptor; 37 38 /** 39 * The base class "color" property 40 * creates both an IndexedPropertyDescriptor which has a conflicting 41 * type for getColor. 42 */ 43 public class Test4168833 { 44 public static void main(String[] args) throws Exception { 45 /* 46 IndexedPropertyDescriptor ipd = BeanUtils.getIndexedPropertyDescriptor(Base.class, "prop"); 47 if (!ipd.getIndexedPropertyType().equals(Dimension.class)) { 48 error(ipd, "Base.prop property should a Dimension"); 49 } 50 */ 51 // When the Sub class is introspected, 52 // the property type should be color. 53 // The complete "classic" set of properties 54 // has been completed accross the hierarchy. 55 test(Sub.class); 56 test(Sub2.class); 57 } 58 59 private static void test(Class type) { 60 PropertyDescriptor pd = BeanUtils.getPropertyDescriptor(type, "prop"); 61 if (pd instanceof IndexedPropertyDescriptor) { 62 error(pd, type.getSimpleName() + ".prop should not be an indexed property"); 63 } 64 if (!pd.getPropertyType().equals(Color.class)) { 65 error(pd, type.getSimpleName() + ".prop type should be a Color"); 66 } 67 if (null == pd.getReadMethod()) { 68 error(pd, type.getSimpleName() + ".prop should have classic read method"); 69 } 70 if (null == pd.getWriteMethod()) { 71 error(pd, type.getSimpleName() + ".prop should have classic write method"); 72 } 73 } 74 75 private static void error(PropertyDescriptor pd, String message) { 76 BeanUtils.reportPropertyDescriptor(pd); 77 throw new Error(message); 78 } 79 80 public static class Base { 81 public Color getProp() { 82 return null; 83 } 84 85 public Dimension getProp(int i) { 86 return null; 87 } 88 } 89 90 public static class Sub extends Base { 91 public void setProp(Color c) { 92 } 93 } 94 95 public static class Base2 { 96 public void setProp(Color c) { 97 } 98 99 public void setProp(int i, Dimension d) { 100 } 101 } 102 103 public static class Sub2 extends Base2 { 104 public Color getProp() { 105 return null; 106 } 107 } 108 }