提交 40192a8b 编写于 作者: M mullan

Merge

...@@ -40,6 +40,22 @@ public class DefaultAsynchronousChannelProvider { ...@@ -40,6 +40,22 @@ public class DefaultAsynchronousChannelProvider {
*/ */
private DefaultAsynchronousChannelProvider() { } 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. * Returns the default AsynchronousChannelProvider.
*/ */
...@@ -47,12 +63,11 @@ public class DefaultAsynchronousChannelProvider { ...@@ -47,12 +63,11 @@ public class DefaultAsynchronousChannelProvider {
String osname = AccessController String osname = AccessController
.doPrivileged(new GetPropertyAction("os.name")); .doPrivileged(new GetPropertyAction("os.name"));
if (osname.equals("SunOS")) if (osname.equals("SunOS"))
return new SolarisAsynchronousChannelProvider(); return createProvider("sun.nio.ch.SolarisAsynchronousChannelProvider");
if (osname.equals("Linux")) if (osname.equals("Linux"))
return new LinuxAsynchronousChannelProvider(); return createProvider("sun.nio.ch.LinuxAsynchronousChannelProvider");
if (osname.contains("OS X")) if (osname.contains("OS X"))
return new BsdAsynchronousChannelProvider(); return createProvider("sun.nio.ch.BsdAsynchronousChannelProvider");
throw new InternalError("platform not recognized"); throw new InternalError("platform not recognized");
} }
} }
...@@ -27,7 +27,6 @@ package sun.nio.ch; ...@@ -27,7 +27,6 @@ package sun.nio.ch;
import java.nio.channels.spi.SelectorProvider; import java.nio.channels.spi.SelectorProvider;
import java.security.AccessController; import java.security.AccessController;
import java.security.PrivilegedAction;
import sun.security.action.GetPropertyAction; import sun.security.action.GetPropertyAction;
/** /**
...@@ -41,34 +40,32 @@ public class DefaultSelectorProvider { ...@@ -41,34 +40,32 @@ public class DefaultSelectorProvider {
*/ */
private DefaultSelectorProvider() { } private DefaultSelectorProvider() { }
/** @SuppressWarnings("unchecked")
* Returns the default SelectorProvider. private static SelectorProvider createProvider(String cn) {
*/ Class<SelectorProvider> c;
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 { try {
int major = Integer.parseInt(vers[0]); c = (Class<SelectorProvider>)Class.forName(cn);
int minor = Integer.parseInt(vers[1]); } catch (ClassNotFoundException x) {
if (major > 2 || (major == 2 && minor >= 6)) { throw new AssertionError(x);
return new sun.nio.ch.EPollSelectorProvider();
}
} catch (NumberFormatException x) {
// format not recognized
} }
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 (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(); return new sun.nio.ch.PollSelectorProvider();
} }
......
...@@ -27,7 +27,6 @@ package sun.nio.fs; ...@@ -27,7 +27,6 @@ package sun.nio.fs;
import java.nio.file.spi.FileSystemProvider; import java.nio.file.spi.FileSystemProvider;
import java.security.AccessController; import java.security.AccessController;
import java.security.PrivilegedAction;
import sun.security.action.GetPropertyAction; import sun.security.action.GetPropertyAction;
/** /**
...@@ -38,24 +37,18 @@ public class DefaultFileSystemProvider { ...@@ -38,24 +37,18 @@ public class DefaultFileSystemProvider {
private DefaultFileSystemProvider() { } private DefaultFileSystemProvider() { }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private static FileSystemProvider createProvider(final String cn) { private static FileSystemProvider createProvider(String cn) {
return AccessController
.doPrivileged(new PrivilegedAction<FileSystemProvider>() {
public FileSystemProvider run() {
Class<FileSystemProvider> c; Class<FileSystemProvider> c;
try { try {
c = (Class<FileSystemProvider>)Class.forName(cn, true, null); c = (Class<FileSystemProvider>)Class.forName(cn);
} catch (ClassNotFoundException x) { } catch (ClassNotFoundException x) {
throw new AssertionError(x); throw new AssertionError(x);
} }
try { try {
return c.newInstance(); return c.newInstance();
} catch (IllegalAccessException x) { } catch (IllegalAccessException | InstantiationException x) {
throw new AssertionError(x);
} catch (InstantiationException x) {
throw new AssertionError(x); throw new AssertionError(x);
} }
}});
} }
/** /**
...@@ -68,7 +61,7 @@ public class DefaultFileSystemProvider { ...@@ -68,7 +61,7 @@ public class DefaultFileSystemProvider {
return createProvider("sun.nio.fs.SolarisFileSystemProvider"); return createProvider("sun.nio.fs.SolarisFileSystemProvider");
if (osname.equals("Linux")) if (osname.equals("Linux"))
return createProvider("sun.nio.fs.LinuxFileSystemProvider"); 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"); return createProvider("sun.nio.fs.MacOSXFileSystemProvider");
throw new AssertionError("Platform not recognized"); throw new AssertionError("Platform not recognized");
} }
......
/* /*
* 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -21,75 +21,97 @@ ...@@ -21,75 +21,97 @@
* questions. * questions.
*/ */
/** /* @test
* See ClassnameCharTest.sh for details. * @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.io.*;
import java.net.*; import java.net.*;
import java.security.*; import java.util.jar.*;
import com.sun.net.httpserver.*;
import sun.applet.AppletClassLoader; import sun.applet.AppletClassLoader;
public class ClassnameCharTest implements HttpCallback { public class ClassnameCharTest {
private static String FNPrefix; static String FNPrefix = System.getProperty("test.src", ".") + File.separator;
private String[] respBody = new String[52]; static File classesJar = new File(FNPrefix + "testclasses.jar");
private byte[][] bufs = new byte[52][8*1024]; static HttpServer server;
private static MessageDigest md5;
private static byte[] file1Mac, file2Mac; public static void realMain(String[] args) throws Exception {
public void request (HttpTransaction req) { server = HttpServer.create(new InetSocketAddress(0), 0);
server.createContext("/", new HttpHandler() {
@Override
public void handle(HttpExchange exchange) {
try { try {
String filename = req.getRequestURI().getPath(); String filename = exchange.getRequestURI().getPath();
System.out.println("getRequestURI = "+req.getRequestURI()); System.out.println("getRequestURI = " + exchange.getRequestURI());
System.out.println("filename = "+filename); System.out.println("filename = " + filename);
FileInputStream fis = new FileInputStream(FNPrefix+filename); try (FileInputStream fis = new FileInputStream(classesJar);
req.setResponseEntityBody(fis); JarInputStream jis = new JarInputStream(fis)) {
req.sendResponse(200, "OK"); JarEntry entry;
req.orderlyClose(); 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) { } catch (IOException e) {
e.printStackTrace(); unexpected(e);
} }
} }
static HttpServer server; });
server.start();
public static void test () throws Exception {
try { try {
URL base = new URL("http://localhost:" + server.getAddress().getPort());
FNPrefix = System.getProperty("test.classes", ".")+"/"; System.out.println ("Server: listening on " + base);
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());
MyAppletClassLoader acl = new MyAppletClassLoader(base); MyAppletClassLoader acl = new MyAppletClassLoader(base);
Class class1 = acl.findClass("fo o"); Class<?> class1 = acl.findClass("fo o");
System.out.println("class1 = "+class1); System.out.println("class1 = " + class1);
pass();
// can't test the following class unless platform in unicode locale // can't test the following class unless platform in unicode locale
// Class class2 = acl.findClass("\u624b\u518c"); // Class class2 = acl.findClass("\u624b\u518c");
// System.out.println("class2 = "+class2); // System.out.println("class2 = "+class2);
} catch (Exception e) { } finally {
if (server != null) { server.stop(0);
server.terminate();
} }
throw e;
} }
server.terminate(); static class MyAppletClassLoader extends AppletClassLoader {
}
public static void main(String[] args) throws Exception {
test();
}
public static void except (String s) {
server.terminate();
throw new RuntimeException (s);
}
}
class MyAppletClassLoader extends AppletClassLoader {
MyAppletClassLoader(URL base) { MyAppletClassLoader(URL base) {
super(base); super(base);
} }
public Class findClass(String name) throws ClassNotFoundException { @Override
public Class<?> findClass(String name) throws ClassNotFoundException {
return super.findClass(name); return super.findClass(name);
} }
}
//--------------------- 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");}
} }
#! /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
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册