changeset 5857:e8a3807de977

7197637: (ch) sun.nio.ch.Default* cause providers for other platforms to be included in rt.jar Reviewed-by: mchung
author alanb
date Thu, 13 Sep 2012 15:04:01 +0100
parents e095be3820ee
children c11cec5a9306
files src/solaris/classes/sun/nio/ch/DefaultAsynchronousChannelProvider.java src/solaris/classes/sun/nio/ch/DefaultSelectorProvider.java src/solaris/classes/sun/nio/fs/DefaultFileSystemProvider.java
diffstat 3 files changed, 54 insertions(+), 49 deletions(-) [+]
line wrap: on
line diff
--- a/src/solaris/classes/sun/nio/ch/DefaultAsynchronousChannelProvider.java	Thu Sep 13 11:17:08 2012 +0100
+++ b/src/solaris/classes/sun/nio/ch/DefaultAsynchronousChannelProvider.java	Thu Sep 13 15:04:01 2012 +0100
@@ -40,6 +40,22 @@
      */
     private DefaultAsynchronousChannelProvider() { }
 
+    @SuppressWarnings("unchecked")
+    private static AsynchronousChannelProvider createProvider(String cn) {
+        Class<AsynchronousChannelProvider> c;
+        try {
+            c = (Class<AsynchronousChannelProvider>)Class.forName(cn);
+        } catch (ClassNotFoundException x) {
+            throw new AssertionError(x);
+        }
+        try {
+            return c.newInstance();
+        } catch (IllegalAccessException | InstantiationException x) {
+            throw new AssertionError(x);
+        }
+
+    }
+
     /**
      * Returns the default AsynchronousChannelProvider.
      */
@@ -47,12 +63,11 @@
         String osname = AccessController
             .doPrivileged(new GetPropertyAction("os.name"));
         if (osname.equals("SunOS"))
-            return new SolarisAsynchronousChannelProvider();
+            return createProvider("sun.nio.ch.SolarisAsynchronousChannelProvider");
         if (osname.equals("Linux"))
-            return new LinuxAsynchronousChannelProvider();
+            return createProvider("sun.nio.ch.LinuxAsynchronousChannelProvider");
         if (osname.contains("OS X"))
-            return new BsdAsynchronousChannelProvider();
+            return createProvider("sun.nio.ch.BsdAsynchronousChannelProvider");
         throw new InternalError("platform not recognized");
     }
-
 }
--- a/src/solaris/classes/sun/nio/ch/DefaultSelectorProvider.java	Thu Sep 13 11:17:08 2012 +0100
+++ b/src/solaris/classes/sun/nio/ch/DefaultSelectorProvider.java	Thu Sep 13 15:04:01 2012 +0100
@@ -27,7 +27,6 @@
 
 import java.nio.channels.spi.SelectorProvider;
 import java.security.AccessController;
-import java.security.PrivilegedAction;
 import sun.security.action.GetPropertyAction;
 
 /**
@@ -41,34 +40,32 @@
      */
     private DefaultSelectorProvider() { }
 
+    @SuppressWarnings("unchecked")
+    private static SelectorProvider createProvider(String cn) {
+        Class<SelectorProvider> c;
+        try {
+            c = (Class<SelectorProvider>)Class.forName(cn);
+        } catch (ClassNotFoundException x) {
+            throw new AssertionError(x);
+        }
+        try {
+            return c.newInstance();
+        } catch (IllegalAccessException | InstantiationException x) {
+            throw new AssertionError(x);
+        }
+
+    }
+
     /**
      * Returns the default SelectorProvider.
      */
     public static SelectorProvider create() {
-        String osname = AccessController.doPrivileged(
-            new GetPropertyAction("os.name"));
-        if ("SunOS".equals(osname)) {
-            return new sun.nio.ch.DevPollSelectorProvider();
-        }
-
-        // use EPollSelectorProvider for Linux kernels >= 2.6
-        if ("Linux".equals(osname)) {
-            String osversion = AccessController.doPrivileged(
-                new GetPropertyAction("os.version"));
-            String[] vers = osversion.split("\\.", 0);
-            if (vers.length >= 2) {
-                try {
-                    int major = Integer.parseInt(vers[0]);
-                    int minor = Integer.parseInt(vers[1]);
-                    if (major > 2 || (major == 2 && minor >= 6)) {
-                        return new sun.nio.ch.EPollSelectorProvider();
-                    }
-                } catch (NumberFormatException x) {
-                    // format not recognized
-                }
-            }
-        }
-
+        String osname = AccessController
+            .doPrivileged(new GetPropertyAction("os.name"));
+        if (osname.equals("SunOS"))
+            return createProvider("sun.nio.ch.DevPollSelectorProvider");
+        if (osname.equals("Linux"))
+            return createProvider("sun.nio.ch.EPollSelectorProvider");
         return new sun.nio.ch.PollSelectorProvider();
     }
 
--- a/src/solaris/classes/sun/nio/fs/DefaultFileSystemProvider.java	Thu Sep 13 11:17:08 2012 +0100
+++ b/src/solaris/classes/sun/nio/fs/DefaultFileSystemProvider.java	Thu Sep 13 15:04:01 2012 +0100
@@ -27,7 +27,6 @@
 
 import java.nio.file.spi.FileSystemProvider;
 import java.security.AccessController;
-import java.security.PrivilegedAction;
 import sun.security.action.GetPropertyAction;
 
 /**
@@ -38,24 +37,18 @@
     private DefaultFileSystemProvider() { }
 
     @SuppressWarnings("unchecked")
-    private static FileSystemProvider createProvider(final String cn) {
-        return AccessController
-            .doPrivileged(new PrivilegedAction<FileSystemProvider>() {
-                public FileSystemProvider run() {
-                    Class<FileSystemProvider> c;
-                    try {
-                        c = (Class<FileSystemProvider>)Class.forName(cn, true, null);
-                    } catch (ClassNotFoundException x) {
-                        throw new AssertionError(x);
-                    }
-                    try {
-                        return c.newInstance();
-                    } catch (IllegalAccessException x) {
-                        throw new AssertionError(x);
-                    } catch (InstantiationException x) {
-                        throw new AssertionError(x);
-                    }
-            }});
+    private static FileSystemProvider createProvider(String cn) {
+        Class<FileSystemProvider> c;
+        try {
+            c = (Class<FileSystemProvider>)Class.forName(cn);
+        } catch (ClassNotFoundException x) {
+            throw new AssertionError(x);
+        }
+        try {
+            return c.newInstance();
+        } catch (IllegalAccessException | InstantiationException x) {
+            throw new AssertionError(x);
+        }
     }
 
     /**
@@ -68,7 +61,7 @@
             return createProvider("sun.nio.fs.SolarisFileSystemProvider");
         if (osname.equals("Linux"))
             return createProvider("sun.nio.fs.LinuxFileSystemProvider");
-        if (osname.equals("Darwin") || osname.contains("OS X"))
+        if (osname.contains("OS X"))
             return createProvider("sun.nio.fs.MacOSXFileSystemProvider");
         throw new AssertionError("Platform not recognized");
     }