Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/beans/XMLEncoder/ReferenceToNonStaticField.java
41152 views
1
/*
2
* Copyright (c) 2015, 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.awt.font.TextAttribute;
25
26
/**
27
* @test
28
* @bug 8060027
29
* @run main/othervm -Djava.security.manager=allow ReferenceToNonStaticField
30
*/
31
public final class ReferenceToNonStaticField
32
extends AbstractTest<ReferenceToNonStaticField.TestValue> {
33
34
public static final class TestValue {
35
36
// reference to static field
37
public TextAttribute font_default = TextAttribute.FONT;
38
public TextAttribute family_default = TextAttribute.FAMILY;
39
public TextAttribute family_set1; // will be set to the same as default
40
public TextAttribute family_set2; // will be set to the same as default
41
public TextAttribute family_set3; // will be set to the same as default
42
43
// primitive small
44
public int int_1_default = 1;
45
public int int_10_default = 10;
46
public int int_10_set1; // will be set to the same as default
47
public int int_10_set2; // will be set to the same as default
48
public int int_10_set3; // will be set to the same as default
49
50
// primitive big
51
public int int_1000_default = 1000;
52
public int int_2000_default = 2000;
53
public int int_2000_set1; // will be set to the same as default
54
public int int_2000_set2; // will be set to the same as default
55
public int int_2000_set3; // will be set to the same as default
56
57
// wrappers
58
public Integer integer_1_default = new Integer(1);
59
public Integer integer_10_default = new Integer(10);
60
public Integer integer_10_set1; // will be set to the same as default
61
public Integer integer_10_set2; // will be set to the same as default
62
public Integer integer_10_set3; // will be set to the same as default
63
64
public TestValue() {
65
}
66
67
public TestValue(final Object ignored) {
68
// set some fields to non-default values, so they will be saved
69
family_set1 = family_default;
70
family_set3 = family_default;
71
family_set2 = family_default;
72
int_10_set1 = int_10_default;
73
int_10_set2 = int_10_default;
74
int_10_set3 = int_10_default;
75
int_2000_set1 = int_2000_default;
76
int_2000_set2 = int_2000_default;
77
int_2000_set3 = int_2000_default;
78
integer_10_set1 = integer_10_default;
79
integer_10_set2 = integer_10_default;
80
integer_10_set3 = integer_10_default;
81
}
82
}
83
84
public static void main(final String[] args) {
85
new ReferenceToNonStaticField().test(true);
86
}
87
88
protected TestValue getObject() {
89
return new TestValue(new Object());
90
}
91
92
@Override
93
protected void validate(final TestValue before,final TestValue after) {
94
super.validate(before, after);
95
validate(before);
96
validate(after);
97
}
98
99
private static void validate(final TestValue object) {
100
// reference to static field
101
if (object.font_default != TextAttribute.FONT) {
102
throw new Error("Wrong font_default: " + object.font_default);
103
}
104
if (object.family_default != TextAttribute.FAMILY) {
105
throw new Error("Wrong family_default: " + object.family_default);
106
}
107
if (object.family_set1 != object.family_default) {
108
throw new Error("Wrong family_set1: " + object.family_set1);
109
}
110
if (object.family_set2 != object.family_default) {
111
throw new Error("Wrong family_set2: " + object.family_set2);
112
}
113
if (object.family_set3 != object.family_default) {
114
throw new Error("Wrong family_set3: " + object.family_set3);
115
}
116
// primitive small
117
if (object.int_1_default != 1) {
118
throw new Error("Wrong int_1_default: " + object.int_1_default);
119
}
120
if (object.int_10_default != 10) {
121
throw new Error("Wrong int_10_default: " + object.int_10_default);
122
}
123
if (object.int_10_set1 != object.int_10_default) {
124
throw new Error("Wrong int_10_set1: " + object.int_10_set1);
125
}
126
if (object.int_10_set2 != object.int_10_default) {
127
throw new Error("Wrong int_10_set2: " + object.int_10_set2);
128
}
129
if (object.int_10_set3 != object.int_10_default) {
130
throw new Error("Wrong int_10_set3: " + object.int_10_set3);
131
}
132
// primitive big
133
if (object.int_1000_default != 1000) {
134
throw new Error("Wrong int_1000_default: " + object.int_1000_default);
135
}
136
if (object.int_2000_default != 2000) {
137
throw new Error("Wrong int_2000_default: " + object.int_2000_default);
138
}
139
if (object.int_2000_set1 != object.int_2000_default) {
140
throw new Error("Wrong int_2000_set1: " + object.int_2000_set1);
141
}
142
if (object.int_2000_set2 != object.int_2000_default) {
143
throw new Error("Wrong int_2000_set2: " + object.int_2000_set2);
144
}
145
if (object.int_2000_set3 != object.int_2000_default) {
146
throw new Error("Wrong int_2000_set3: " + object.int_2000_set3);
147
}
148
// wrappers
149
if (!object.integer_1_default.equals(new Integer(1))) {
150
throw new Error("Wrong integer_1_default: " + object.integer_1_default);
151
}
152
if (!object.integer_10_default.equals(new Integer(10))) {
153
throw new Error("Wrong integer_10_default: " + object.integer_10_default);
154
}
155
if (object.integer_10_set1 != object.integer_10_default) {
156
throw new Error("Wrong integer_10_set1: " + object.integer_10_set1);
157
}
158
if (object.integer_10_set2 != object.integer_10_default) {
159
throw new Error("Wrong integer_10_set2: " + object.integer_10_set2);
160
}
161
if (object.integer_10_set3 != object.integer_10_default) {
162
throw new Error("Wrong integer_10_set3: " + object.integer_10_set3);
163
}
164
}
165
}
166
167