jdk/src/java.base/windows/classes/java/net/DefaultDatagramSocketImplFactory.java
changeset 32503 1478c9130534
parent 25859 3317bb8137f4
child 32649 2ee9017c7597
--- a/jdk/src/java.base/windows/classes/java/net/DefaultDatagramSocketImplFactory.java	Wed Sep 09 12:39:45 2015 +0300
+++ b/jdk/src/java.base/windows/classes/java/net/DefaultDatagramSocketImplFactory.java	Wed Sep 09 16:33:19 2015 +0300
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2007, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2007, 2015, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -45,7 +45,7 @@
 
 class DefaultDatagramSocketImplFactory
 {
-    static Class<?> prefixImplClass = null;
+    private final static Class<?> prefixImplClass;
 
     /* the windows version. */
     private static float version;
@@ -54,16 +54,19 @@
     private static boolean preferIPv4Stack = false;
 
     /* If the version supports a dual stack TCP implementation */
-    private static boolean useDualStackImpl = false;
+    private final static boolean useDualStackImpl;
 
     /* sun.net.useExclusiveBind */
     private static String exclBindProp;
 
     /* True if exclusive binding is on for Windows */
-    private static boolean exclusiveBind = true;
-
+    private final static boolean exclusiveBind;
 
     static {
+        Class<?> prefixImplClassLocal = null;
+        boolean useDualStackImplLocal = false;
+        boolean exclusiveBindLocal = true;
+
         // Determine Windows Version.
         java.security.AccessController.doPrivileged(
                 new PrivilegedAction<Object>() {
@@ -78,7 +81,7 @@
                                                    "java.net.preferIPv4Stack"));
                             exclBindProp = System.getProperty(
                                     "sun.net.useExclusiveBind");
-                        } catch (NumberFormatException e ) {
+                        } catch (NumberFormatException e) {
                             assert false : e;
                         }
                         return null; // nothing to return
@@ -87,14 +90,14 @@
 
         // (version >= 6.0) implies Vista or greater.
         if (version >= 6.0 && !preferIPv4Stack) {
-                useDualStackImpl = true;
+            useDualStackImplLocal = true;
         }
         if (exclBindProp != null) {
             // sun.net.useExclusiveBind is true
-            exclusiveBind = exclBindProp.length() == 0 ? true
+            exclusiveBindLocal = exclBindProp.length() == 0 ? true
                     : Boolean.parseBoolean(exclBindProp);
         } else if (version < 6.0) {
-            exclusiveBind = false;
+            exclusiveBindLocal = false;
         }
 
         // impl.prefix
@@ -103,12 +106,16 @@
             prefix = AccessController.doPrivileged(
                 new sun.security.action.GetPropertyAction("impl.prefix", null));
             if (prefix != null)
-                prefixImplClass = Class.forName("java.net."+prefix+"DatagramSocketImpl");
+                prefixImplClassLocal = Class.forName("java.net."+prefix+"DatagramSocketImpl");
         } catch (Exception e) {
             System.err.println("Can't find class: java.net." +
                                 prefix +
                                 "DatagramSocketImpl: check impl.prefix property");
         }
+
+        prefixImplClass = prefixImplClassLocal;
+        useDualStackImpl = useDualStackImplLocal;
+        exclusiveBind = exclusiveBindLocal;
     }
 
     /**
@@ -126,12 +133,10 @@
                 throw new SocketException("can't instantiate DatagramSocketImpl");
             }
         } else {
-            if (isMulticast)
-                exclusiveBind = false;
             if (useDualStackImpl && !isMulticast)
                 return new DualStackPlainDatagramSocketImpl(exclusiveBind);
             else
-                return new TwoStacksPlainDatagramSocketImpl(exclusiveBind);
+                return new TwoStacksPlainDatagramSocketImpl(exclusiveBind && !isMulticast);
         }
     }
 }