Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/beans/Introspector/OverloadedSetter.java
41149 views
1
/*
2
* Copyright (c) 2018, 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
import java.beans.BeanInfo;
25
import java.beans.Introspector;
26
import java.beans.PropertyDescriptor;
27
import java.lang.reflect.Method;
28
29
/**
30
* @test
31
* @bug 8196373
32
* @summary behavior of this class is not specified, but it can be used to check
33
* our implementation for accidental changes
34
*/
35
public final class OverloadedSetter {
36
37
class AAA {}
38
class CCC extends AAA {}
39
class BBB extends CCC {}
40
class DDD extends CCC {}
41
42
class ZZZ {}
43
44
// DDD will be selected because it is most specific type.
45
class ParentADC<T> {
46
public void setValue(AAA value) {}
47
public void setValue(DDD value) {}
48
public void setValue(CCC value) {}
49
}
50
// DDD will be selected because it is most specific type.
51
class ParentACD<T> {
52
public void setValue(AAA value) {}
53
public void setValue(CCC value) {}
54
public void setValue(DDD value) {}
55
}
56
// DDD will be selected because it is most specific type.
57
class ParentDAC<T> {
58
public void setValue(DDD value) {}
59
public void setValue(AAA value) {}
60
public void setValue(CCC value) {}
61
}
62
// DDD will be selected because it is most specific type.
63
class ParentDCA<T> {
64
public void setValue(DDD value) {}
65
public void setValue(CCC value) {}
66
public void setValue(AAA value) {}
67
}
68
// DDD will be selected because it is most specific type.
69
class ParentCAD<T> {
70
public void setValue(CCC value) {}
71
public void setValue(AAA value) {}
72
public void setValue(DDD value) {}
73
}
74
// DDD will be selected because it is most specific type.
75
class ParentCDA<T> {
76
public void setValue(CCC value) {}
77
public void setValue(DDD value) {}
78
public void setValue(AAA value) {}
79
}
80
// DDD will be selected because it is most specific type and ZZZ will be
81
// skipped because it will be placed at the end of the methods list.
82
class ParentCDAZ<T> {
83
public void setValue(CCC value) {}
84
public void setValue(DDD value) {}
85
public void setValue(AAA value) {}
86
public void setValue(ZZZ value) {}
87
}
88
// DDD will be selected because it is most specific type which related to
89
// the type of getValue(); BBB will be skipped because it is not a type or
90
// subclass of the type returned by getValue();
91
class ParentDACB<T> {
92
public DDD getValue(){return null;}
93
public void setValue(AAA value) {}
94
public void setValue(DDD value) {}
95
public void setValue(CCC value) {}
96
public void setValue(BBB value) {}
97
}
98
99
public static void main(String[] args) throws Exception {
100
test(ParentADC.class);
101
test(ParentACD.class);
102
test(ParentDAC.class);
103
test(ParentDCA.class);
104
test(ParentCAD.class);
105
test(ParentCDA.class);
106
test(ParentCDAZ.class);
107
test(ParentDACB.class);
108
}
109
110
private static void test(Class<?> beanClass) throws Exception {
111
BeanInfo beanInfo = Introspector.getBeanInfo(beanClass, Object.class);
112
PropertyDescriptor[] pds = beanInfo.getPropertyDescriptors();
113
if (pds.length != 1) {
114
throw new RuntimeException("Wrong number of properties");
115
}
116
PropertyDescriptor pd = pds[0];
117
String name = pd.getName();
118
if (!name.equals("value")) {
119
throw new RuntimeException("Wrong name: " + name);
120
}
121
122
Class<?> propertyType = pd.getPropertyType();
123
if (propertyType != DDD.class) {
124
throw new RuntimeException("Wrong property type: " + propertyType);
125
}
126
Method writeMethod = pd.getWriteMethod();
127
if (writeMethod == null) {
128
throw new RuntimeException("Write method is null");
129
}
130
Class<?>[] parameterTypes = writeMethod.getParameterTypes();
131
if (parameterTypes.length != 1) {
132
throw new RuntimeException("Wrong parameters " + parameterTypes);
133
}
134
if (parameterTypes[0] != DDD.class) {
135
throw new RuntimeException("Wrong type: " + parameterTypes[0]);
136
}
137
}
138
}
139
140