Path: blob/master/test/jdk/java/beans/Introspector/4520754/Test4520754.java
41153 views
/*1* Copyright (c) 2002, 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 4168475 452075426* @summary Tests for the removal of some of the exception based control flow27* @author Mark Davidson28*/2930import infos.ComponentBeanInfo;3132import java.awt.Button;33import java.awt.Component;34import java.awt.List;35import java.awt.Menu;36import java.awt.Panel;3738import java.beans.BeanInfo;39import java.beans.IntrospectionException;40import java.beans.Introspector;41import java.beans.PropertyDescriptor;4243import javax.swing.JApplet;44import javax.swing.JButton;45import javax.swing.JCheckBox;4647public class Test4520754 {48/**49* This is here to force the BeanInfo classes to be compiled50*/51private static final Class[] COMPILE = {52ComponentBeanInfo.class,53FooBarBeanInfo.class,54WombatBeanInfo.class,55};5657public static void main(String[] args) {58// ensure that 4168475 does not regress59test4168475(Component.class);60// AWT classes (com.sun.beans.infos.ComponentBeanInfo)61test(null, Button.class, Component.class, List.class, Menu.class, Panel.class);62// Swing classes (dt.jar)63test(null, JApplet.class, JButton.class, JCheckBox.class);64// user defined classes65test(Boolean.TRUE, Wombat.class, Foo.class, FooBar.class);66}6768private static void test(Boolean mark, Class... types) {69for (Class type : types) {70BeanInfo info = getBeanInfo(mark, type);71if (info == null) {72throw new Error("could not find BeanInfo for " + type);73}74if (mark != info.getBeanDescriptor().getValue("test")) {75throw new Error("could not find marked BeanInfo for " + type);76}77}78Introspector.flushCaches();79}8081private static BeanInfo getBeanInfo(Boolean mark, Class type) {82System.out.println("test=" + mark + " for " + type);83BeanInfo info;84try {85info = Introspector.getBeanInfo(type);86} catch (IntrospectionException exception) {87throw new Error("unexpected exception", exception);88}89if (info == null) {90throw new Error("could not find BeanInfo for " + type);91}92if (mark != info.getBeanDescriptor().getValue("test")) {93throw new Error("could not find marked BeanInfo for " + type);94}95return info;96}9798/**99* This is a regression test to ensure that 4168475 does not regress.100*/101private static void test4168475(Class type) {102String[] newPath = {"infos"};103String[] oldPath = Introspector.getBeanInfoSearchPath();104105Introspector.setBeanInfoSearchPath(newPath);106BeanInfo info = getBeanInfo(Boolean.TRUE, type);107Introspector.setBeanInfoSearchPath(oldPath);108109PropertyDescriptor[] pds = info.getPropertyDescriptors();110if (pds.length != 1) {111throw new Error("could not find custom BeanInfo for " + type);112}113Introspector.flushCaches();114}115}116117118