I am trying to learn about the Java resolution model. I tried this code example:
public static void main(String[] args) { File file = new File("/etc/passwd"); try (BufferedReader reader = new BufferedReader(new FileReader(file));) { reader.lines().forEach(s -> System.out.println(s)); } catch (IOException e) { e.printStackTrace(); } FilePermission perm = new FilePermission("/etc/passwd", "read"); AccessController.checkPermission(perm);
This prints the contents of /etc/passwd fine, but at the end throws an exception:
Exception in thread "main" java.security.AccessControlException: access denied ("java.io.FilePermission" "" "read")
Why is reading the file working fine, but checking the resolution gives a negative result?
source share