Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/javax/security/auth/callback/Mutability.java
41153 views
1
/*
2
* Copyright (c) 2020, 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 8242330
27
* @library /test/lib
28
* @summary Arrays should be cloned in several JAAS Callback classes
29
*/
30
31
import javax.security.auth.callback.ChoiceCallback;
32
import javax.security.auth.callback.ConfirmationCallback;
33
34
import static jdk.test.lib.Asserts.assertEQ;
35
36
public class Mutability {
37
public static void main(String[] args) {
38
39
// #1. ConfirmationCallback.new(3)
40
String[] i11 = {"1", "2"};
41
ConfirmationCallback c1 = new ConfirmationCallback(
42
ConfirmationCallback.INFORMATION,
43
i11,
44
0);
45
46
// Modify argument of constructor
47
i11[0] = "x";
48
String[] o11 = c1.getOptions();
49
assertEQ(o11[0], "1");
50
// Modify output
51
o11[0] = "y";
52
String[] o12 = c1.getOptions();
53
assertEQ(o12[0], "1");
54
55
// #2. ConfirmationCallback.new(4)
56
String[] i21 = {"1", "2"};
57
ConfirmationCallback c2 = new ConfirmationCallback(
58
"Hi",
59
ConfirmationCallback.INFORMATION,
60
i21,
61
0);
62
63
// Modify argument of constructor
64
i21[0] = "x";
65
assertEQ(c2.getOptions()[0], "1");
66
67
// #3. ChoiceCallback.new
68
String[] i31 = {"1", "2"};
69
ChoiceCallback c3 = new ChoiceCallback(
70
"Hi",
71
i31,
72
0,
73
true);
74
75
// Modify argument of constructor
76
i31[0] = "x";
77
String[] o31 = c3.getChoices();
78
assertEQ(o31[0], "1");
79
// Modify output of getChoices
80
o31[0] = "y";
81
String[] o32 = c3.getChoices();
82
assertEQ(o32[0], "1");
83
84
int[] s31 = {0, 1};
85
c3.setSelectedIndexes(s31);
86
87
// Modify argument of setSelectedIndexes
88
s31[0] = 1;
89
int[] s32 = c3.getSelectedIndexes();
90
assertEQ(s32[0], 0);
91
// Modify output of getSelectedIndexes
92
s32[1] = 0;
93
int[] s33 = c3.getSelectedIndexes();
94
assertEQ(s33[1], 1);
95
}
96
}
97
98