Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running JUnit tests with IntelliJ IDEA - "java.security.AccessControlException"

I'm trying to run JUnit tests using IntelliJ Idea 11.1. But the tests are giving different AccessControlExceptions. One of them are below. But these tests run without a problem in Eclipse.

Exception in thread "main" java.security.AccessControlException: access denied (java.lang.RuntimePermission setIO)
    at java.security.AccessControlContext.checkPermission(AccessControlContext.java:374)
    at java.security.AccessController.checkPermission(AccessController.java:546)
    at java.lang.SecurityManager.checkPermission(SecurityManager.java:532)
    at java.lang.System.checkIO(System.java:225)
    at java.lang.System.setOut(System.java:147)
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:202)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:63)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)

Do I need to set special permissions of some kind for the IDEA test runner? If so how?

like image 827
Nufail Avatar asked Oct 07 '22 00:10

Nufail


2 Answers

I just ran into this problem myself, to at least get things running, I copied the java.policy file from <jdk>/jre/lib/security and added the following permissions in the default grant to get the tests running under IntelliJ IDEA 2016.2:

    // To get tests working under IntelliJ 2016.2
    permission java.util.PropertyPermission "idea.launcher.bin.path", "read";
    permission java.lang.RuntimePermission "loadLibrary.C:\\Program Files (x86)\\JetBrains\\IntelliJ IDEA 2016.2\\bin\\breakgen64.dll";
    permission java.util.PropertyPermission "idea.launcher.port", "read";
    permission java.lang.reflect.ReflectPermission "suppressAccessChecks";
    permission java.util.PropertyPermission "idea.is.junit5", "read";
    permission java.net.SocketPermission "127.0.0.1:*", "connect,resolve";
    permission java.util.PropertyPermission "user.home", "read";
    permission java.io.FilePermission "C:\\Users\\Mark\\junit.properties", "read";
    permission java.lang.RuntimePermission "setIO";
    permission java.io.FilePermission "C:\\Users\\Mark\\AppData\\Local\\Temp\\*", "read";
    permission java.lang.RuntimePermission "accessDeclaredMembers";

You will need to change some of the paths to suit your specific user needs. With these changes I am not yet completely done: I still seem to be missing some permissions specific to my own code (specifically: reading a number of property files from my own code).

like image 130
Mark Rotteveel Avatar answered Oct 13 '22 12:10

Mark Rotteveel


Create a file C:\utils\grant_all.policy with content

// Grant everyone all permissions:
grant {
 permission java.security.AllPermission;
};

and add in the debug configuration in IntelliJ

like image 34
O. Fauch. Avatar answered Oct 13 '22 12:10

O. Fauch.