changeset 5860:c11cec5a9306

Merge
author mullan
date Fri, 14 Sep 2012 10:30:38 -0400
parents 34bcbb110bb0 e8a3807de977
children 22d7a9f73a59
files test/sun/misc/URLClassPath/ClassnameCharTest.sh
diffstat 5 files changed, 131 insertions(+), 164 deletions(-) [+]
line wrap: on
line diff
--- a/src/solaris/classes/sun/nio/ch/DefaultAsynchronousChannelProvider.java	Fri Sep 14 10:14:15 2012 -0400
+++ b/src/solaris/classes/sun/nio/ch/DefaultAsynchronousChannelProvider.java	Fri Sep 14 10:30:38 2012 -0400
@@ -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	Fri Sep 14 10:14:15 2012 -0400
+++ b/src/solaris/classes/sun/nio/ch/DefaultSelectorProvider.java	Fri Sep 14 10:30:38 2012 -0400
@@ -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	Fri Sep 14 10:14:15 2012 -0400
+++ b/src/solaris/classes/sun/nio/fs/DefaultFileSystemProvider.java	Fri Sep 14 10:30:38 2012 -0400
@@ -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");
     }
--- a/test/sun/misc/URLClassPath/ClassnameCharTest.java	Fri Sep 14 10:14:15 2012 -0400
+++ b/test/sun/misc/URLClassPath/ClassnameCharTest.java	Fri Sep 14 10:30:38 2012 -0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 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
@@ -21,75 +21,97 @@
  * questions.
  */
 
-/**
- * See ClassnameCharTest.sh for details.
+/* @test
+ * @bug 4957669 5017871
+ * @compile -XDignore.symbol.file=true ClassnameCharTest.java
+ * @run main ClassnameCharTest
+ * @summary cannot load class names containing some JSR 202 characters;
+ *          plugin does not escape unicode character in http request
  */
 
 import java.io.*;
 import java.net.*;
-import java.security.*;
+import java.util.jar.*;
+import com.sun.net.httpserver.*;
 import sun.applet.AppletClassLoader;
 
-public class ClassnameCharTest implements HttpCallback {
-    private static String FNPrefix;
-    private String[] respBody = new String[52];
-    private byte[][] bufs = new byte[52][8*1024];
-    private static MessageDigest md5;
-    private static byte[] file1Mac, file2Mac;
-    public void request (HttpTransaction req) {
-        try {
-            String filename = req.getRequestURI().getPath();
-            System.out.println("getRequestURI = "+req.getRequestURI());
-            System.out.println("filename = "+filename);
-            FileInputStream fis = new FileInputStream(FNPrefix+filename);
-            req.setResponseEntityBody(fis);
-            req.sendResponse(200, "OK");
-            req.orderlyClose();
-        } catch (IOException e) {
-            e.printStackTrace();
-        }
-    }
+public class ClassnameCharTest {
+    static String FNPrefix = System.getProperty("test.src", ".") + File.separator;
+    static File classesJar = new File(FNPrefix + "testclasses.jar");
     static HttpServer server;
 
-    public static void test () throws Exception {
+    public static void realMain(String[] args) throws Exception {
+        server = HttpServer.create(new InetSocketAddress(0), 0);
+        server.createContext("/", new HttpHandler() {
+            @Override
+            public void handle(HttpExchange exchange) {
+                try {
+                    String filename = exchange.getRequestURI().getPath();
+                    System.out.println("getRequestURI = " + exchange.getRequestURI());
+                    System.out.println("filename = " + filename);
+                    try (FileInputStream fis = new FileInputStream(classesJar);
+                         JarInputStream jis = new JarInputStream(fis)) {
+                        JarEntry entry;
+                        while ((entry = jis.getNextJarEntry()) != null) {
+                            if (filename.endsWith(entry.getName())) {
+                                ByteArrayOutputStream baos = new ByteArrayOutputStream();
+                                byte[] buf = new byte[8092];
+                                int count = 0;
+                                while ((count = jis.read(buf)) != -1)
+                                    baos.write(buf, 0, count);
+                                exchange.sendResponseHeaders(200, baos.size());
+                                try (OutputStream os = exchange.getResponseBody()) {
+                                    baos.writeTo(os);
+                                }
+                                return;
+                            }
+                        }
+                        fail("Failed to find " + filename);
+                    }
+                } catch (IOException e) {
+                    unexpected(e);
+                }
+            }
+        });
+        server.start();
         try {
-
-            FNPrefix = System.getProperty("test.classes", ".")+"/";
-            server = new HttpServer (new ClassnameCharTest(), 1, 10, 0);
-            System.out.println ("Server: listening on port: " + server.getLocalPort());
-            URL base = new URL("http://localhost:"+server.getLocalPort());
+            URL base = new URL("http://localhost:" + server.getAddress().getPort());
+            System.out.println ("Server: listening on " + base);
             MyAppletClassLoader acl = new MyAppletClassLoader(base);
-            Class class1 = acl.findClass("fo o");
-            System.out.println("class1 = "+class1);
+            Class<?> class1 = acl.findClass("fo o");
+            System.out.println("class1 = " + class1);
+            pass();
             // can't test the following class unless platform in unicode locale
             // Class class2 = acl.findClass("\u624b\u518c");
             // System.out.println("class2 = "+class2);
-        } catch (Exception e) {
-            if (server != null) {
-                server.terminate();
-            }
-            throw e;
+        } finally {
+            server.stop(0);
+        }
+    }
+
+    static class MyAppletClassLoader extends AppletClassLoader {
+        MyAppletClassLoader(URL base) {
+            super(base);
         }
 
-        server.terminate();
+        @Override
+        public Class<?> findClass(String name) throws ClassNotFoundException {
+            return super.findClass(name);
+        }
     }
 
-    public static void main(String[] args) throws Exception {
-        test();
-    }
-
-    public static void except (String s) {
-        server.terminate();
-        throw new RuntimeException (s);
-    }
+    //--------------------- Infrastructure ---------------------------
+    static volatile int passed = 0, failed = 0;
+    static boolean pass() {passed++; return true;}
+    static boolean fail() {failed++; server.stop(0); Thread.dumpStack(); return false;}
+    static boolean fail(String msg) {System.out.println(msg); return fail();}
+    static void unexpected(Throwable t) {failed++; server.stop(0); t.printStackTrace();}
+    static boolean check(boolean cond) {if (cond) pass(); else fail(); return cond;}
+    static boolean equal(Object x, Object y) {
+        if (x == null ? y == null : x.equals(y)) return pass();
+        else return fail(x + " not equal to " + y);}
+    public static void main(String[] args) throws Throwable {
+        try {realMain(args);} catch (Throwable t) {unexpected(t);}
+        System.out.println("\nPassed = " + passed + " failed = " + failed);
+        if (failed > 0) throw new AssertionError("Some tests failed");}
 }
-
-class MyAppletClassLoader extends AppletClassLoader {
-    MyAppletClassLoader(URL base) {
-        super(base);
-    }
-
-    public Class findClass(String name) throws ClassNotFoundException {
-        return super.findClass(name);
-    }
-}
--- a/test/sun/misc/URLClassPath/ClassnameCharTest.sh	Fri Sep 14 10:14:15 2012 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,60 +0,0 @@
-#! /bin/sh
-
-#
-# Copyright (c) 2004, 2010, 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
-# under the terms of the GNU General Public License version 2 only, as
-# published by the Free Software Foundation.
-#
-# This code is distributed in the hope that it will be useful, but WITHOUT
-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
-# version 2 for more details (a copy is included in the LICENSE file that
-# accompanied this code).
-#
-# You should have received a copy of the GNU General Public License version
-# 2 along with this work; if not, write to the Free Software Foundation,
-# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
-#
-# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
-# or visit www.oracle.com if you need additional information or have any
-# questions.
-#
-
-# @test
-# @author Yingxian Wang
-# @bug 4957669 5017871
-# @library ../../../sun/net/www/httptest/
-# @build HttpCallback HttpServer ClosedChannelList HttpTransaction
-# @run shell/timeout=300 ClassnameCharTest.sh
-# @summary ; cannot load class names containing some JSR 202 characters;
-#          plugin does not escape unicode character in http request
-#
-# set platform-dependent variables
-
-OS=`uname -s`
-case "$OS" in
-  SunOS | Linux | Darwin )
-    PS=":"
-    FS="/"
-    ;;
-  Windows* | CYGWIN* )
-    PS=";"
-    FS="\\"
-    ;;
-  * )
-    echo "Unrecognized system!"
-    exit 1;
-    ;;
-esac
-
-cp ${TESTSRC}${FS}testclasses.jar ${TESTCLASSES}
-cd ${TESTCLASSES}
-${TESTJAVA}${FS}bin${FS}jar xvf testclasses.jar "fo o.class"
-${TESTJAVA}${FS}bin${FS}javac -d ${TESTCLASSES} ${TESTSRC}${FS}ClassnameCharTest.java
-
-${TESTJAVA}${FS}bin${FS}java -classpath "${TESTCLASSES}${PS}${TESTCLASSES}${FS}sun${FS}misc${FS}URLClassPath" ClassnameCharTest
-
-rm -rf "fo o.class" testclasses.jar