Better ForkJoinPool behavior in OpenJDK 8

Solution Verified - Updated -

Issue

  • Running java class for example: Test2.java throws an exception

    import java.io.FilePermission;
    import java.security.AccessController;
    import java.util.concurrent.ForkJoinPool;
    import java.util.concurrent.ForkJoinWorkerThread;
    import java.util.concurrent.RecursiveTask;
    
    public class Test2 {
    
        static void testPermission() {
            AccessController.checkPermission(new FilePermission(System.getProperty("java.class.path")+"/a", "read"));
        }
    
        public static void main(String[] args){
            testPermission();
    
            ForkJoinPool pool = new ForkJoinPool(1);
    
            pool.invoke(new RecursiveTask<Object>() {
                @Override
                protected Object compute() {
                    testPermission();
                    System.out.println("done");
                    return null;
                }
            });
    
            pool.shutdown();
        }
    }
    
  • The exception is:

    Exception in thread "main" java.security.AccessControlException: access denied ("java.io.FilePermission" "./a" "read")
            at java.security.AccessControlContext.checkPermission(AccessControlContext.java:472)
            at java.security.AccessController.checkPermission(AccessController.java:886)
            at Test2.testPermission(Test2.java:10)
            at Test2$1.compute(Test2.java:21)
            at java.util.concurrent.RecursiveTask.exec(RecursiveTask.java:94)
            at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
            at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
            at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
            at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:163)
    

Environment

  • Red Hat OpenJDK
    • 8u265
    • 8u272
    • 8u275

Subscriber exclusive content

A Red Hat subscription provides unlimited access to our knowledgebase of over 48,000 articles and solutions.

Current Customers and Partners

Log in for full access

Log In