JDK11, Security policies doesn’t get propagated to ForkJoinPool worker threads

706 Views Asked by At
public class S3ButcketTest
{

public static void main(String args[])
{
    System.setSecurityManager(new RMISecurityManager());
    ForkJoinPool pool = new ForkJoinPool(1);
    System.out.println("main: "+Policy.getPolicy());

    pool.execute(new Runnable()
    {
        @Override
        public void run()
        {
            try
            {
                Thread.sleep(1000);
            }
            catch (InterruptedException e)
            {
                e.printStackTrace();
            }
            System.out.println("pool: "+Policy.getPolicy());
        }
    });

    pool.shutdown();
    try
    {
        pool.awaitTermination(1000, TimeUnit.SECONDS);
    }
    catch (InterruptedException e)
    {
        e.printStackTrace();
    }
}
}

Running on two different JDK versions (8 & 11) with VM argument: -Djava.security.policy=C:\test_system.policy

test_system.policy Content:

grant {
permission java.security.AllPermission;
};

Output when running with JDK11:

main: sun.security.provider.PolicyFile@4cb2c100
Exception in thread "ForkJoinPool-1-worker-3" java.security.AccessControlException: access denied ("java.security.SecurityPermission" "getPolicy")
at java.base/java.security.AccessControlContext.checkPermission(AccessControlContext.java:472)
at java.base/java.security.AccessController.checkPermission(AccessController.java:895)
at java.base/java.lang.SecurityManager.checkPermission(SecurityManager.java:322)
at java.base/java.security.Policy.getPolicy(Policy.java:159)
at S3ButcketTest$1.run(S3ButcketTest.java:30)
at java.base/java.util.concurrent.ForkJoinTask$RunnableExecuteAction.exec(ForkJoinTask.java:1426)
at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:290)
at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1020)
at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1656)
at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1594)
at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:177)

Output when running with JDK8:

main: sun.security.provider.PolicyFile@1b84c92
pool: sun.security.provider.PolicyFile@1b84c92

We upgraded our JDK from 8 to 11 and suddenly we are facing this problem. Is there any explanation of why this is happening? Any solution?

0

There are 0 best solutions below