6

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?

8
  • are you running them from the menu? Are you using Spring to run them or just simple JUnit? Also are you using System.out... in your tests? Looks like something is trying to set this from the stack trace
    – RNJ
    Aug 4, 2012 at 8:40
  • 1
    Do you run with custom -Djava.security.policy?
    – CrazyCoder
    Aug 4, 2012 at 10:31
  • @user846476 yes. I'm running them using Run command in menu. It is simple JUnit. I checked test file and there are no System.out...s
    – Nufail
    Aug 6, 2012 at 0:15
  • @CrazyCoder no I don't use that option
    – Nufail
    Aug 6, 2012 at 0:16
  • Have you tried using an external build tool? Maven, ant? It sound like an IntelliJ problem. Ive never seen it before. If it runs ok in maven/ant then I would assume the test set up is alright and then perhaps it is a IntelliJ problem. Re-install?
    – RNJ
    Aug 6, 2012 at 18:24

3 Answers 3

2

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).

2

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

1

As I wasn't to keen to just grant all permissions on the JVM I've updated Mark Rotteveel solution to also allow debugging in IntelliJ. It just needed 3 additional permissions:

permission java.util.PropertyPermission "idea.launcher.bin.path", "read";
    permission java.lang.RuntimePermission "loadLibrary.C:\\Program Files\\JetBrains\\IntelliJ IDEA Community Edition 2019.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\\David\\junit.properties", "read";
    permission java.lang.RuntimePermission "setIO";
    permission java.io.FilePermission "C:\\Users\\David\\AppData\\Local\\Temp\\*", "read";
    permission java.lang.RuntimePermission "accessDeclaredMembers";

    // Additional properties needed to allow debugging in IntelliJ
    permission java.io.FilePermission "C:\\Program Files\\JetBrains\\IntelliJ IDEA Community Edition 2019.2\\bin\\breakgen64.dll", "read";
    permission java.util.PropertyPermission "intellij.debug.agent", "read";
    permission java.util.PropertyPermission "intellij.debug.agent", "write";

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.