Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/io/FilePermission/FilePermissionCollectionMerge.java
41149 views
1
/*
2
* Copyright (c) 2016, 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
*
26
* @test
27
* @bug 8168127
28
* @summary FilePermissionCollection merges incorrectly
29
* @modules java.base/sun.security.util
30
* @library /test/lib
31
* @build jdk.test.lib.Asserts
32
* @run main FilePermissionCollectionMerge
33
*/
34
35
import sun.security.util.FilePermCompat;
36
import java.io.FilePermission;
37
import java.security.Permissions;
38
import jdk.test.lib.Asserts;
39
40
public class FilePermissionCollectionMerge {
41
42
public static void main(String[] args) throws Exception {
43
test("x");
44
test("x/*");
45
test("x/-");
46
test("*");
47
test("-");
48
test("/x");
49
test("/x/*");
50
test("/x/-");
51
}
52
53
static void test(String arg) {
54
55
FilePermission fp1 = new FilePermission(arg, "read");
56
FilePermission fp2 = (FilePermission)
57
FilePermCompat.newPermUsingAltPath(fp1);
58
FilePermission fp3 = (FilePermission)
59
FilePermCompat.newPermPlusAltPath(fp1);
60
61
// All 3 are different
62
Asserts.assertNE(fp1, fp2);
63
Asserts.assertNE(fp1.hashCode(), fp2.hashCode());
64
65
Asserts.assertNE(fp1, fp3);
66
Asserts.assertNE(fp1.hashCode(), fp3.hashCode());
67
68
Asserts.assertNE(fp2, fp3);
69
Asserts.assertNE(fp2.hashCode(), fp3.hashCode());
70
71
// The plus one implies the other 2
72
Asserts.assertTrue(fp3.implies(fp1));
73
Asserts.assertTrue(fp3.implies(fp2));
74
75
// The using one different from original
76
Asserts.assertFalse(fp2.implies(fp1));
77
Asserts.assertFalse(fp1.implies(fp2));
78
79
// FilePermssionCollection::implies always works
80
testMerge(fp1);
81
testMerge(fp2);
82
testMerge(fp3);
83
testMerge(fp1, fp2);
84
testMerge(fp1, fp3);
85
testMerge(fp2, fp1);
86
testMerge(fp2, fp3);
87
testMerge(fp3, fp1);
88
testMerge(fp3, fp2);
89
testMerge(fp1, fp2, fp3);
90
testMerge(fp2, fp3, fp1);
91
testMerge(fp3, fp1, fp2);
92
}
93
94
// Add all into a collection, and check if it implies the last one.
95
static void testMerge(FilePermission... fps) {
96
java.security.Permissions perms = new Permissions();
97
FilePermission last = null;
98
for (FilePermission fp : fps) {
99
perms.add(fp);
100
last = fp;
101
}
102
Asserts.assertTrue(perms.implies(last));
103
}
104
}
105
106