6706208: (cs) CharsetProvider permission check cleanup
authoralanb
Mon, 16 Dec 2013 19:52:55 +0000
changeset 22053 09b848a5794d
parent 22052 07af87cd2302
child 22054 503bc3781dfe
6706208: (cs) CharsetProvider permission check cleanup Reviewed-by: chegar, mchung
jdk/src/share/classes/java/nio/channels/spi/SelectorProvider.java
jdk/src/share/classes/java/nio/charset/spi/CharsetProvider.java
--- a/jdk/src/share/classes/java/nio/channels/spi/SelectorProvider.java	Mon Dec 16 15:05:26 2013 +0000
+++ b/jdk/src/share/classes/java/nio/channels/spi/SelectorProvider.java	Mon Dec 16 19:52:55 2013 +0000
@@ -71,6 +71,14 @@
     private static final Object lock = new Object();
     private static SelectorProvider provider = null;
 
+    private static Void checkPermission() {
+        SecurityManager sm = System.getSecurityManager();
+        if (sm != null)
+            sm.checkPermission(new RuntimePermission("selectorProvider"));
+        return null;
+    }
+    private SelectorProvider(Void ignore) { }
+
     /**
      * Initializes a new instance of this class.
      *
@@ -79,9 +87,7 @@
      *          {@link RuntimePermission}<tt>("selectorProvider")</tt>
      */
     protected SelectorProvider() {
-        SecurityManager sm = System.getSecurityManager();
-        if (sm != null)
-            sm.checkPermission(new RuntimePermission("selectorProvider"));
+        this(checkPermission());
     }
 
     private static boolean loadProviderFromProperty() {
--- a/jdk/src/share/classes/java/nio/charset/spi/CharsetProvider.java	Mon Dec 16 15:05:26 2013 +0000
+++ b/jdk/src/share/classes/java/nio/charset/spi/CharsetProvider.java	Mon Dec 16 19:52:55 2013 +0000
@@ -71,6 +71,14 @@
 
 public abstract class CharsetProvider {
 
+    private static Void checkPermission() {
+        SecurityManager sm = System.getSecurityManager();
+        if (sm != null)
+            sm.checkPermission(new RuntimePermission("charsetProvider"));
+        return null;
+    }
+    private CharsetProvider(Void ignore) { }
+
     /**
      * Initializes a new charset provider.
      *
@@ -79,9 +87,7 @@
      *          {@link RuntimePermission}<tt>("charsetProvider")</tt>
      */
     protected CharsetProvider() {
-        SecurityManager sm = System.getSecurityManager();
-        if (sm != null)
-            sm.checkPermission(new RuntimePermission("charsetProvider"));
+        this(checkPermission());
     }
 
     /**