changeset 9145:e1ec864c1548

7197203: sun/misc/URLClassPath/ClassnameCharTest.sh failed, compile error Reviewed-by: alanb
author chegar
date Thu, 20 Apr 2017 06:26:56 +0100
parents 0f6def68b385
children c630b72e39d9
files test/sun/misc/URLClassPath/ClassnameCharTest.java test/sun/misc/URLClassPath/ClassnameCharTest.sh
diffstat 2 files changed, 77 insertions(+), 115 deletions(-) [+]
line wrap: on
line diff
--- a/test/sun/misc/URLClassPath/ClassnameCharTest.java	Wed Jan 25 18:16:48 2017 +0300
+++ b/test/sun/misc/URLClassPath/ClassnameCharTest.java	Thu Apr 20 06:26:56 2017 +0100
@@ -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();
-    }
-
-    public static void main(String[] args) throws Exception {
-        test();
+        @Override
+        public Class<?> findClass(String name) throws ClassNotFoundException {
+            return super.findClass(name);
+        }
     }
 
-    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	Wed Jan 25 18:16:48 2017 +0300
+++ /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 | AIX )
-    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