JDK-8167478 : javax/xml/jaxp/unittest/parsers/Bug6341770.java failed with "java.security.AccessControlException: access denied ("java.io.FilePermission" "sko?ice")"
  • Type: Bug
  • Component: xml
  • Sub-Component: jaxp
  • Affected Version: 9
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • Submitted: 2016-10-11
  • Updated: 2016-10-20
  • Resolved: 2016-10-17
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 9
9 b141Fixed
Related Reports
Relates :  
Description
[TestNG] Running:
  javax/xml/jaxp/unittest/parsers/Bug6341770.java

test parsers.Bug6341770.testNonAsciiURI(): failure
java.lang.AssertionError: Exception: access denied ("java.io.FilePermission" "sko?ice")
	at org.testng.Assert.fail(Assert.java:94)
	at parsers.Bug6341770.testNonAsciiURI(Bug6341770.java:81)
	at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(java.base@9-ea/Native Method)
	at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(java.base@9-ea/NativeMethodAccessorImpl.java:62)
	at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(java.base@9-ea/DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(java.base@9-ea/Method.java:535)
	at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:85)
	at org.testng.internal.Invoker.invokeMethod(Invoker.java:639)
	at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:821)
	at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1131)
	at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:124)
	at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:108)
	at org.testng.TestRunner.privateRun(TestRunner.java:773)
	at org.testng.TestRunner.run(TestRunner.java:623)
	at org.testng.SuiteRunner.runTest(SuiteRunner.java:357)
	at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:352)
	at org.testng.SuiteRunner.privateRun(SuiteRunner.java:310)
	at org.testng.SuiteRunner.run(SuiteRunner.java:259)
	at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
	at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
	at org.testng.TestNG.runSuitesSequentially(TestNG.java:1185)
	at org.testng.TestNG.runSuitesLocally(TestNG.java:1110)
	at org.testng.TestNG.run(TestNG.java:1018)
	at com.sun.javatest.regtest.TestNGAction$TestNGRunner.main(TestNGAction.java:220)
	at com.sun.javatest.regtest.TestNGAction$TestNGRunner.main(TestNGAction.java:184)
	at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(java.base@9-ea/Native Method)
	at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(java.base@9-ea/NativeMethodAccessorImpl.java:62)
	at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(java.base@9-ea/DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(java.base@9-ea/Method.java:535)
	at com.sun.javatest.regtest.agent.MainWrapper$MainThread.run(MainWrapper.java:110)
	at java.lang.Thread.run(java.base@9-ea/Thread.java:843)

===============================================
javax/xml/jaxp/unittest/parsers/Bug6341770.java
Total tests run: 1, Failures: 1, Skips: 0
===============================================

----------System.err:(50/3615)----------
java.security.AccessControlException: access denied ("java.io.FilePermission" "sko?ice")
	at java.security.AccessControlContext.checkPermission(java.base@9-ea/AccessControlContext.java:471)
	at java.security.AccessController.checkPermission(java.base@9-ea/AccessController.java:894)
	at java.lang.SecurityManager.checkPermission(java.base@9-ea/SecurityManager.java:548)
	at java.lang.SecurityManager.checkDelete(java.base@9-ea/SecurityManager.java:1006)
	at java.io.File.delete(java.base@9-ea/File.java:1037)
	at parsers.Bug6341770.testNonAsciiURI(Bug6341770.java:58)
	at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(java.base@9-ea/Native Method)
	at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(java.base@9-ea/NativeMethodAccessorImpl.java:62)
	at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(java.base@9-ea/DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(java.base@9-ea/Method.java:535)
	at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:85)
	at org.testng.internal.Invoker.invokeMethod(Invoker.java:639)
	at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:821)
	at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1131)
	at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:124)
	at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:108)
	at org.testng.TestRunner.privateRun(TestRunner.java:773)
	at org.testng.TestRunner.run(TestRunner.java:623)
	at org.testng.SuiteRunner.runTest(SuiteRunner.java:357)
	at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:352)
	at org.testng.SuiteRunner.privateRun(SuiteRunner.java:310)
	at org.testng.SuiteRunner.run(SuiteRunner.java:259)
	at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
	at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
	at org.testng.TestNG.runSuitesSequentially(TestNG.java:1185)
	at org.testng.TestNG.runSuitesLocally(TestNG.java:1110)
	at org.testng.TestNG.run(TestNG.java:1018)
	at com.sun.javatest.regtest.TestNGAction$TestNGRunner.main(TestNGAction.java:220)
	at com.sun.javatest.regtest.TestNGAction$TestNGRunner.main(TestNGAction.java:184)
	at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(java.base@9-ea/Native Method)
	at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(java.base@9-ea/NativeMethodAccessorImpl.java:62)
	at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(java.base@9-ea/DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(java.base@9-ea/Method.java:535)
	at com.sun.javatest.regtest.agent.MainWrapper$MainThread.run(MainWrapper.java:110)
	at java.lang.Thread.run(java.base@9-ea/Thread.java:843)
java.lang.Exception: failures: 1
	at com.sun.javatest.regtest.TestNGAction$TestNGRunner.main(TestNGAction.java:223)
	at com.sun.javatest.regtest.TestNGAction$TestNGRunner.main(TestNGAction.java:184)
	at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(java.base@9-ea/Native Method)
	at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(java.base@9-ea/NativeMethodAccessorImpl.java:62)
	at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(java.base@9-ea/DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(java.base@9-ea/Method.java:535)
	at com.sun.javatest.regtest.agent.MainWrapper$MainThread.run(MainWrapper.java:110)
	at java.lang.Thread.run(java.base@9-ea/Thread.java:843)
Comments
This bug exposes the problem in Bug6341770.java, even though it was passed before 8164705 was introduced, the test is invalid in the ascii environment because it actually created an ascii character path. So I will revise the test to make it exit directly when the system charset doesn't support non-ascii.
13-10-2016

[~fyuan] Great investigation. I've assigned the bug to myself. Update: Assign back to Frank. I am not planning to make any change on the io/security side at the moment. Please make change to this test. My suggestion is to avoid creating such a file if the platform does not support it. For example, if Paths.get("sko\u0159ice") throws an exception, the test can return immediately. A warning can be printed.
12-10-2016

I am sure it's not related to xml because I reproduce this issue with the following program: import java.io.File; import java.io.FilePermission; import java.nio.charset.Charset; import java.security.Permission; import java.security.PermissionCollection; import java.security.Permissions; import java.security.Policy; import java.security.ProtectionDomain; public class TestFilePermission { public static void main(String[] args) { System.out.println(Charset.defaultCharset().toString()); String userdir = System.getProperty("user.dir"); File dir = new File("sko\u0159ice"); System.out.println(dir.getPath()); TestPolicy p = new TestPolicy(); Policy.setPolicy(p); p.addPermission(new FilePermission(userdir + "/-", "read,write,delete")); System.setSecurityManager(new SecurityManager()); dir.delete(); } } class TestPolicy extends Policy { private final PermissionCollection permissions = new Permissions(); public void addPermission(Permission p) { permissions.add(p); } @Override public boolean implies(ProtectionDomain domain, Permission perm) { return permissions.implies(perm); } } Run java TestFilePermission after setting the environment variable LANG=C But java -Dfile.encoding=US-ASCII TestFilePermission won't trigger the issue, I am not sure the difference.
12-10-2016

The ultimate reason is that the name is invalid as a file name. The following expression Paths.get("sko\u0159ice"); throws java.nio.file.InvalidPathException: Malformed input or input contains unmappable characters: sko?ice at sun.nio.fs.UnixPath.encode(java.base/UnixPath.java:145) at sun.nio.fs.UnixPath.<init>(java.base/UnixPath.java:69) at sun.nio.fs.UnixFileSystem.getPath(java.base/UnixFileSystem.java:280) at java.nio.file.Paths.get(java.base/Paths.java:84) Since FilePermission is now based on NIO 2 Path, such a FilePermission will never be granted.
12-10-2016