Sergey Malenkov | 9e33696 | 2013-11-08 14:09:18 +0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2013, 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 | import java.beans.IndexedPropertyDescriptor; |
| 25 | import java.beans.PropertyDescriptor; |
| 26 | |
| 27 | /* |
| 28 | * @test |
| 29 | * @bug 8027648 |
| 30 | * @summary Tests overridden getter and overloaded setter |
| 31 | * @author Sergey Malenkov |
| 32 | */ |
| 33 | |
| 34 | public class Test8027648 { |
| 35 | |
| 36 | public static void main(String[] args) { |
| 37 | test(false); |
| 38 | test(true); |
| 39 | } |
| 40 | |
| 41 | private static void test(boolean indexed) { |
| 42 | Class<?> parent = getPropertyType(BaseBean.class, indexed); |
| 43 | Class<?> child = getPropertyType(MyBean.class, indexed); |
| 44 | if (parent.equals(child) || !parent.isAssignableFrom(child)) { |
| 45 | throw new Error("the child property type is not override the parent property type"); |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | private static Class<?> getPropertyType(Class<?> type, boolean indexed) { |
| 50 | PropertyDescriptor pd = BeanUtils.findPropertyDescriptor(type, indexed ? "index" : "value"); |
| 51 | if (pd instanceof IndexedPropertyDescriptor) { |
| 52 | IndexedPropertyDescriptor ipd = (IndexedPropertyDescriptor) pd; |
| 53 | return ipd.getIndexedPropertyType(); |
| 54 | } |
| 55 | return pd.getPropertyType(); |
| 56 | } |
| 57 | |
| 58 | public static class BaseBean { |
| 59 | private Object value; |
| 60 | |
| 61 | public Object getValue() { |
| 62 | return this.value; |
| 63 | } |
| 64 | |
| 65 | public void setValue(Object value) { |
| 66 | this.value = value; |
| 67 | } |
| 68 | |
| 69 | public Object getIndex(int index) { |
| 70 | return getValue(); |
| 71 | } |
| 72 | |
| 73 | public void setIndex(int index, Object value) { |
| 74 | setValue(value); |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | public static class MyBean extends BaseBean { |
| 79 | @Override |
| 80 | public String getValue() { |
| 81 | return (String) super.getValue(); |
| 82 | } |
| 83 | |
| 84 | public void setValue(String value) { |
| 85 | setValue((Object) value); |
| 86 | } |
| 87 | |
| 88 | @Override |
| 89 | public String getIndex(int index) { |
| 90 | return getValue(); |
| 91 | } |
| 92 | |
| 93 | public void setIndex(int index, String value) { |
| 94 | setValue(value); |
| 95 | } |
| 96 | } |
| 97 | } |