Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/beans/Introspector/Test8005065.java
47964 views
1
/*
2
* Copyright (c) 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 8005065
27
* @summary Tests that all arrays in JavaBeans are guarded
28
* @author Sergey Malenkov
29
*/
30
31
import java.beans.DefaultPersistenceDelegate;
32
import java.beans.Encoder;
33
import java.beans.EventSetDescriptor;
34
import java.beans.ExceptionListener;
35
import java.beans.Expression;
36
import java.beans.Statement;
37
import java.beans.MethodDescriptor;
38
import java.beans.ParameterDescriptor;
39
40
public class Test8005065 {
41
42
public static void main(String[] args) {
43
testDefaultPersistenceDelegate();
44
testEventSetDescriptor();
45
testMethodDescriptor();
46
testStatement();
47
}
48
49
private static void testDefaultPersistenceDelegate() {
50
Encoder encoder = new Encoder();
51
String[] array = { "array" };
52
MyDPD dpd = new MyDPD(array);
53
dpd.instantiate(dpd, encoder);
54
array[0] = null;
55
dpd.instantiate(dpd, encoder);
56
}
57
58
private static void testEventSetDescriptor() {
59
try {
60
MethodDescriptor[] array = { new MethodDescriptor(MyDPD.class.getMethod("getArray")) };
61
EventSetDescriptor descriptor = new EventSetDescriptor(null, null, array, null, null);
62
test(descriptor.getListenerMethodDescriptors());
63
array[0] = null;
64
test(descriptor.getListenerMethodDescriptors());
65
descriptor.getListenerMethodDescriptors()[0] = null;
66
test(descriptor.getListenerMethodDescriptors());
67
}
68
catch (Exception exception) {
69
throw new Error("unexpected error", exception);
70
}
71
}
72
73
private static void testMethodDescriptor() {
74
try {
75
ParameterDescriptor[] array = { new ParameterDescriptor() };
76
MethodDescriptor descriptor = new MethodDescriptor(MyDPD.class.getMethod("getArray"), array);
77
test(descriptor.getParameterDescriptors());
78
array[0] = null;
79
test(descriptor.getParameterDescriptors());
80
descriptor.getParameterDescriptors()[0] = null;
81
test(descriptor.getParameterDescriptors());
82
}
83
catch (Exception exception) {
84
throw new Error("unexpected error", exception);
85
}
86
}
87
88
private static void testStatement() {
89
Object[] array = { new Object() };
90
Statement statement = new Statement(null, null, array);
91
test(statement.getArguments());
92
array[0] = null;
93
test(statement.getArguments());
94
statement.getArguments()[0] = null;
95
test(statement.getArguments());
96
}
97
98
private static <T> void test(T[] array) {
99
if (array.length != 1) {
100
throw new Error("unexpected array length");
101
}
102
if (array[0] == null) {
103
throw new Error("unexpected array content");
104
}
105
}
106
107
public static class MyDPD
108
extends DefaultPersistenceDelegate
109
implements ExceptionListener {
110
111
private final String[] array;
112
113
public MyDPD(String[] array) {
114
super(array);
115
this.array = array;
116
}
117
118
public Expression instantiate(Object instance, Encoder encoder) {
119
encoder.setExceptionListener(this);
120
return super.instantiate(instance, encoder);
121
}
122
123
public String[] getArray() {
124
return this.array;
125
}
126
127
public void exceptionThrown(Exception exception) {
128
throw new Error("unexpected error", exception);
129
}
130
}
131
}
132
133