javajava-8javapolicy

java.net.SocketPermission for localhost won't work on Java 1.8 but with your local IP it does


I have a seemingly strange problem with the Java 8 Policy.

I used the following permission in Java 7 up to update 51 and it worked fine:

grant { 
    (...)
    java.net.SocketPermission "localhost:1024-", "accept,connect,listen,resolve";
};

But now I'm checking Java 8 Support, and i get this Exception:

Exception in thread "RMI TCP Connection(idle)" java.security.AccessControlException: access denied ("java.net.SocketPermission" "10.1.17.112:55703" "accept,resolve")
at java.security.AccessControlContext.checkPermission(Unknown Source)
at java.security.AccessController.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkPermission(Unknown Source)
at sun.plugin2.applet.AWTAppletSecurityManager.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkAccept(Unknown Source)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.checkAcceptPermission(Unknown Source)
at sun.rmi.transport.tcp.TCPTransport.checkAcceptPermission(Unknown Source)
at sun.rmi.transport.Transport$1.run(Unknown Source)
at sun.rmi.transport.Transport$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Unknown Source)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(Unknown Source)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(Unknown Source)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

Running IPConfig shows me that 10.1.17.122 is the IP of my local machine:

   Ethernet adapter Local Area Connection:

   IPv4 Address. . . . . . . . . . . : 10.1.17.112
   Subnet Mask . . . . . . . . . . . : 255.255.252.0
   Default Gateway . . . . . . . . . : 10.1.19.254

If I change the permission to 127.0.0.1 it dosent work neither:

grant { 
    (...)
    java.net.SocketPermission "127.0.0.1:1024-", "accept,connect,listen,resolve";
};

BUT, if I enter my IP Address, all works fine again:

grant { 
    (...)
    java.net.SocketPermission "10.1.17.112:1024-", "accept,connect,listen,resolve";
};

Any ideas why?

Edit: For me it seems like a Bug in Java 8, can anyone confirm this?


Solution

  • I think i found what i was looking for: http://bugs.java.com/bugdatabase/view_bug.do?bug_id=7077696

    The suggested workaround there works for me.

    2011-11-09 WORK AROUND

    Run with -Djava.net.preferIPv4Stack=true

    Thanks for your help!