Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/beans/Introspector/Test8027648.java
47964 views
/*1* Copyright (c) 2013, 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 802764829* @summary Tests overridden getter and overloaded setter30* @author Sergey Malenkov31*/3233public class Test8027648 {3435public static void main(String[] args) {36test(false);37test(true);38}3940private static void test(boolean indexed) {41Class<?> parent = getPropertyType(BaseBean.class, indexed);42Class<?> child = getPropertyType(MyBean.class, indexed);43if (parent.equals(child) || !parent.isAssignableFrom(child)) {44throw new Error("the child property type is not override the parent property type");45}46}4748private static Class<?> getPropertyType(Class<?> type, boolean indexed) {49PropertyDescriptor pd = BeanUtils.findPropertyDescriptor(type, indexed ? "index" : "value");50if (pd instanceof IndexedPropertyDescriptor) {51IndexedPropertyDescriptor ipd = (IndexedPropertyDescriptor) pd;52return ipd.getIndexedPropertyType();53}54return pd.getPropertyType();55}5657public static class BaseBean {58private Object value;5960public Object getValue() {61return this.value;62}6364public void setValue(Object value) {65this.value = value;66}6768public Object getIndex(int index) {69return getValue();70}7172public void setIndex(int index, Object value) {73setValue(value);74}75}7677public static class MyBean extends BaseBean {78@Override79public String getValue() {80return (String) super.getValue();81}8283public void setValue(String value) {84setValue((Object) value);85}8687@Override88public String getIndex(int index) {89return getValue();90}9192public void setIndex(int index, String value) {93setValue(value);94}95}96}979899