Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/beans/Introspector/4520754/Test4520754.java
41153 views
1
/*
2
* Copyright (c) 2002, 2012, 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 4168475 4520754
27
* @summary Tests for the removal of some of the exception based control flow
28
* @author Mark Davidson
29
*/
30
31
import infos.ComponentBeanInfo;
32
33
import java.awt.Button;
34
import java.awt.Component;
35
import java.awt.List;
36
import java.awt.Menu;
37
import java.awt.Panel;
38
39
import java.beans.BeanInfo;
40
import java.beans.IntrospectionException;
41
import java.beans.Introspector;
42
import java.beans.PropertyDescriptor;
43
44
import javax.swing.JApplet;
45
import javax.swing.JButton;
46
import javax.swing.JCheckBox;
47
48
public class Test4520754 {
49
/**
50
* This is here to force the BeanInfo classes to be compiled
51
*/
52
private static final Class[] COMPILE = {
53
ComponentBeanInfo.class,
54
FooBarBeanInfo.class,
55
WombatBeanInfo.class,
56
};
57
58
public static void main(String[] args) {
59
// ensure that 4168475 does not regress
60
test4168475(Component.class);
61
// AWT classes (com.sun.beans.infos.ComponentBeanInfo)
62
test(null, Button.class, Component.class, List.class, Menu.class, Panel.class);
63
// Swing classes (dt.jar)
64
test(null, JApplet.class, JButton.class, JCheckBox.class);
65
// user defined classes
66
test(Boolean.TRUE, Wombat.class, Foo.class, FooBar.class);
67
}
68
69
private static void test(Boolean mark, Class... types) {
70
for (Class type : types) {
71
BeanInfo info = getBeanInfo(mark, type);
72
if (info == null) {
73
throw new Error("could not find BeanInfo for " + type);
74
}
75
if (mark != info.getBeanDescriptor().getValue("test")) {
76
throw new Error("could not find marked BeanInfo for " + type);
77
}
78
}
79
Introspector.flushCaches();
80
}
81
82
private static BeanInfo getBeanInfo(Boolean mark, Class type) {
83
System.out.println("test=" + mark + " for " + type);
84
BeanInfo info;
85
try {
86
info = Introspector.getBeanInfo(type);
87
} catch (IntrospectionException exception) {
88
throw new Error("unexpected exception", exception);
89
}
90
if (info == null) {
91
throw new Error("could not find BeanInfo for " + type);
92
}
93
if (mark != info.getBeanDescriptor().getValue("test")) {
94
throw new Error("could not find marked BeanInfo for " + type);
95
}
96
return info;
97
}
98
99
/**
100
* This is a regression test to ensure that 4168475 does not regress.
101
*/
102
private static void test4168475(Class type) {
103
String[] newPath = {"infos"};
104
String[] oldPath = Introspector.getBeanInfoSearchPath();
105
106
Introspector.setBeanInfoSearchPath(newPath);
107
BeanInfo info = getBeanInfo(Boolean.TRUE, type);
108
Introspector.setBeanInfoSearchPath(oldPath);
109
110
PropertyDescriptor[] pds = info.getPropertyDescriptors();
111
if (pds.length != 1) {
112
throw new Error("could not find custom BeanInfo for " + type);
113
}
114
Introspector.flushCaches();
115
}
116
}
117
118