Jai's review - Cleanup & JAR_PATH String -> Path
This commit is contained in:
parent
ab8785ccf0
commit
afda9fe1fa
@ -25,10 +25,8 @@
|
||||
* @bug 4957669 5017871 8358729
|
||||
* @summary cannot load class names containing some JSR 202 characters;
|
||||
* plugin does not escape unicode character in http request
|
||||
* @library /test/lib
|
||||
* @modules java.base/sun.net.www
|
||||
* jdk.httpserver
|
||||
* @compile -XDignore.symbol.file=true ClassnameCharTest.java
|
||||
* @run main ClassnameCharTest
|
||||
*/
|
||||
|
||||
@ -36,15 +34,14 @@ import java.io.*;
|
||||
import java.lang.classfile.ClassFile;
|
||||
import java.lang.constant.ClassDesc;
|
||||
import java.net.*;
|
||||
import java.nio.file.Path;
|
||||
import java.security.CodeSource;
|
||||
import java.util.jar.*;
|
||||
import com.sun.net.httpserver.*;
|
||||
import jdk.test.lib.Utils;
|
||||
import sun.net.www.ParseUtil;
|
||||
|
||||
public class ClassnameCharTest {
|
||||
private static final String JAR_PATH = Utils.TEST_CLASSES + Utils.FILE_SEPARATOR + "testclasses.jar";
|
||||
static File classesJar = new File(JAR_PATH);
|
||||
private static final Path JAR_PATH = Path.of(".").resolve("testclasses.jar");
|
||||
static HttpServer server;
|
||||
|
||||
public static void realMain(String[] args) throws Exception {
|
||||
@ -56,7 +53,7 @@ public class ClassnameCharTest {
|
||||
String filename = exchange.getRequestURI().getPath();
|
||||
System.out.println("getRequestURI = " + exchange.getRequestURI());
|
||||
System.out.println("filename = " + filename);
|
||||
try (FileInputStream fis = new FileInputStream(classesJar);
|
||||
try (FileInputStream fis = new FileInputStream(JAR_PATH.toFile());
|
||||
JarInputStream jis = new JarInputStream(fis)) {
|
||||
JarEntry entry;
|
||||
while ((entry = jis.getNextJarEntry()) != null) {
|
||||
@ -130,12 +127,15 @@ public class ClassnameCharTest {
|
||||
// Make sure the codebase won't be modified
|
||||
if (base.getProtocol().equals(finalURL.getProtocol()) &&
|
||||
base.getHost().equals(finalURL.getHost()) &&
|
||||
base.getPort() == finalURL.getPort()) {
|
||||
base.getPort() == finalURL.getPort() + 1) {
|
||||
byte[] b = getBytes(finalURL);
|
||||
return defineClass(name, b, 0, b.length, codesource);
|
||||
}
|
||||
} catch (Exception _) {}
|
||||
throw new ClassNotFoundException(name);
|
||||
} catch (Exception e) {
|
||||
throw new ClassNotFoundException(name, e);
|
||||
}
|
||||
throw new ClassNotFoundException(
|
||||
"\"%s\" not found - Protocol/Host/Port mismatch".formatted(name));
|
||||
}
|
||||
|
||||
/*
|
||||
@ -216,7 +216,7 @@ public class ClassnameCharTest {
|
||||
// Create the class file and write it to the testable jar
|
||||
static void buildJar() throws IOException {
|
||||
var bytes = ClassFile.of().build(ClassDesc.of("fo o"), _ -> {});
|
||||
try (JarOutputStream jos = new JarOutputStream(new FileOutputStream(JAR_PATH))) {
|
||||
try (JarOutputStream jos = new JarOutputStream(new FileOutputStream(JAR_PATH.toFile()))) {
|
||||
jos.putNextEntry(new JarEntry("fo o.class"));
|
||||
jos.write(bytes, 0, bytes.length);
|
||||
jos.closeEntry();
|
||||
|
Loading…
x
Reference in New Issue
Block a user