< prev index next >
test/java/io/FilePermission/Correctness.java
Print this page
rev 16962 : 8177969: Faster FilePermission::implies by avoiding the use of Path::relativize
@@ -1,7 +1,7 @@
/*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
@@ -87,16 +87,18 @@
//check("/-", "a");
//checkNo("/*", "a");
//check("/-", "-");
try {
- // containsPath is broken on Windows.
containsMethod = FilePermission.class.getDeclaredMethod(
"containsPath", Path.class, Path.class);
containsMethod.setAccessible(true);
System.out.println();
+ // The 1st 2 args of contains() must be normalized paths.
+ // When FilePermission::containsPath is called by implies,
+ // paths have already been normalized.
contains("x", "x", 0);
contains("x", "x/y", 1);
contains("x", "x/y/z", 2);
contains("x", "y", -1);
contains("x", "", -1);
@@ -158,11 +160,11 @@
if (d != expected) {
err = true;
}
}
- static void check(String s1, String s2, boolean expected) {
+ static void check0(String s1, String s2, boolean expected) {
FilePermission fp1 = new FilePermission(s1, "read");
FilePermission fp2 = new FilePermission(s2, "read");
boolean b = fp1.implies(fp2);
System.out.printf("%-30s -> %-30s: %5b %s\n",
s1, s2, b, b==expected?"":" WRONG");
@@ -171,10 +173,20 @@
System.out.println(fp1);
System.out.println(fp2);
}
}
+ static void check(String s1, String s2, boolean expected) {
+ check0(s1, s2, expected);
+ if (isWindows) {
+ check0("C:" + s1, s2, false);
+ check0(s1, "C:" + s2, false);
+ check0("C:" + s1, "D:" + s2, false);
+ check0("C:" + s1, "C:" + s2, expected);
+ }
+ }
+
static void check(String s1, String s2) {
check(s1, s2, true);
}
static void checkNo(String s1, String s2) {
< prev index next >