Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6767891

java.net.ServerSocket ctor on windows requires java.util.PropertyPermission to be granted

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P2 P2
    • None
    • 7
    • core-libs
    • None
    • generic
    • windows

      Trying to create ServerSocket fails on windows if an access to properties is denied.
      The following code works fine on solaris with jdk6, jdk7 and on windows with jdk6; and throws SecurityException on windows with jdk7:

      ----------
      import java.net.ServerSocket;

      public class Test {
          
          public static void main(String[] args) {
              SecurityManager sm = new SecurityManager() {
                  public void checkPropertiesAccess() {
                      throw new SecurityException("Action forbidden ");
                  }
              };
              System.setSecurityManager(sm);
              try {
                  ServerSocket ss = new ServerSocket(5555);
                  ss.close();
                  System.out.println("OK");
              } catch (Exception e) {
                  System.out.println("Ex: " + e);
                  e.printStackTrace(System.out);
                      
              }
          }
      }
      ------------

      The specification states that ServerSocket ctors throws SecurityException - "if a security manager exists and its checkListen method doesn't allow the operation". Nothing is said about the checkPropertiesAccess method.

      The output from the program run on windows XP:

      #> java -version
      java version "1.7.0-ea"
      Java(TM) SE Runtime Environment (build 1.7.0-ea-b38)
      Java HotSpot(TM) Client VM (build 14.0-b05, mixed mode, sharing)

      #> java test
      Exception in thread "main" java.lang.ExceptionInInitializerError
      at java.net.ServerSocket.setImpl(ServerSocket.java:280)
      at java.net.ServerSocket.<init>(ServerSocket.java:221)
      at java.net.ServerSocket.<init>(ServerSocket.java:119)
      at Test.main(Test.java:13)
      Caused by: java.lang.SecurityException: Action forbidden
      at Test$1.checkPropertiesAccess(Test.java:8)
      at java.lang.System.getProperties(System.java:618)
      at java.net.PlainSocketImpl$1.run(PlainSocketImpl.java:62)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.net.PlainSocketImpl.<clinit>(PlainSocketImpl.java:58)
      ... 4 more

            chegar Chris Hegarty
            dfazunen Dmitry Fazunenko (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: