AccessControlException: access denied for a readab

2019-09-14 23:26发布

问题:

I have this file:

➜ ✗ ll ltr /Users/eladb/WorkspaceQa/sdk-service/src/main/resources/convert_conditions.sh

-rwxrwxrwx  1 eladb  eng   882B Jun 11 16:38 /Users/eladb/WorkspaceQa/sdk-service/src/main/resources/convert_conditions.sh

I try to read it from java:

        new FileInputStream(new File("/Users/eladb/WorkspaceQa/sdk-service/src/main/resources/convert_conditions.sh"));

but i get an error:

java.security.AccessControlException: access denied ("java.io.FilePermission" "/Users/eladb/WorkspaceQa/sdk-service/src/main/resources/convert_conditions.sh" "read")
    at java.security.AccessControlContext.checkPermission(AccessControlContext.java:472) ~[?:1.8.0_91]
    at java.security.AccessController.checkPermission(AccessController.java:884) ~[?:1.8.0_91]
    at java.lang.SecurityManager.checkPermission(SecurityManager.java:549) ~[?:1.8.0_91]
    at java.lang.SecurityManager.checkRead(SecurityManager.java:888) ~[?:1.8.0_91]
    at java.io.FileInputStream.<init>(FileInputStream.java:127) ~[?:1.8.0_91]

how come, as everyone has a read permission to that file?

回答1:

The operating system's file permissions have nothing to do with it. See the stack trace, or indeed the Javadoc of the exception. This exception comes from the Java security manager, not the operating system. You are running under a security manager (why?) and you haven't granted yourself permission to access that file in your .policy file.