Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/beans/Introspector/Test7193977.java
47964 views
/*1* Copyright (c) 2012, 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 719397726* @summary Tests that generified property descriptors do not loose additional info27* @author Sergey Malenkov28*/2930import java.awt.Image;31import java.beans.BeanDescriptor;32import java.beans.BeanInfo;33import java.beans.EventSetDescriptor;34import java.beans.IntrospectionException;35import java.beans.Introspector;36import java.beans.MethodDescriptor;37import java.beans.PropertyDescriptor;38import java.util.Arrays;39import java.util.List;4041public class Test7193977 {4243private static final List<String> names = Arrays.asList("listType", "list", "value");4445public static void main(String args[]) {46for (String name : names) {47test(Abstract.class, name);48test(Concrete.class, name);49}50}5152private static void test(Class<?> type, String name) {53if (!Boolean.TRUE.equals(BeanUtils.getPropertyDescriptor(type, name).getValue("transient"))) {54throw new Error("property '" + name + "' is not transient");55}56}5758public static final class Concrete extends Abstract<String> {59}6061public static abstract class Abstract<T> {62private List<T> list;6364public List<T> getList() {65return this.list;66}6768public void setList(List<T> list) {69this.list = list;70}7172public T getValue(int index) {73return (0 <= index) && (this.list != null) && (index < this.list.size())74? this.list.get(index)75: null;76}7778public void setValue(int index, T value) {79if ((0 <= index) && (this.list != null)) {80if (index == this.list.size()) {81this.list.add(value);82}83else if (index < this.list.size()) {84this.list.set(index, value);85}86}87}8889public String getListType() {90return (this.list != null)91? this.list.getClass().getName()92: null;93}9495public void setListType(String type) throws Exception {96this.list = (type != null)97? (List<T>) Class.forName(type).newInstance()98: null;99}100}101102public static final class ConcreteBeanInfo extends Wrapper {103public ConcreteBeanInfo() throws IntrospectionException {104super(Concrete.class);105}106}107108public static final class AbstractBeanInfo extends Wrapper {109public AbstractBeanInfo() throws IntrospectionException {110super(Abstract.class);111for (PropertyDescriptor pd : getPropertyDescriptors()) {112if (names.contains(pd.getName())) {113pd.setValue("transient", Boolean.TRUE);114}115}116}117}118119private static class Wrapper implements BeanInfo {120private final BeanInfo info;121122Wrapper(Class<?> type) throws IntrospectionException {123this.info = Introspector.getBeanInfo(type, Introspector.IGNORE_IMMEDIATE_BEANINFO);124}125126public BeanDescriptor getBeanDescriptor() {127return this.info.getBeanDescriptor();128}129130public EventSetDescriptor[] getEventSetDescriptors() {131return this.info.getEventSetDescriptors();132}133134public int getDefaultEventIndex() {135return this.info.getDefaultEventIndex();136}137138public PropertyDescriptor[] getPropertyDescriptors() {139return this.info.getPropertyDescriptors();140}141142public int getDefaultPropertyIndex() {143return this.info.getDefaultPropertyIndex();144}145146public MethodDescriptor[] getMethodDescriptors() {147return this.info.getMethodDescriptors();148}149150public BeanInfo[] getAdditionalBeanInfo() {151return this.info.getAdditionalBeanInfo();152}153154public Image getIcon(int kind) {155return this.info.getIcon(kind);156}157}158}159160161