changeset 22053:09b848a5794d

6706208: (cs) CharsetProvider permission check cleanup Reviewed-by: chegar, mchung
author alanb
date Mon, 16 Dec 2013 19:52:55 +0000
parents 07af87cd2302
children 503bc3781dfe
files jdk/src/share/classes/java/nio/channels/spi/SelectorProvider.java jdk/src/share/classes/java/nio/charset/spi/CharsetProvider.java
diffstat 2 files changed, 18 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- 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());
     }
 
     /**