8307168: Inconsistent validation and handling of --system flag arguments
Reviewed-by: jjg
This commit is contained in:
parent
5b5fd3694a
commit
957703b1f9
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2003, 2021, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2003, 2023, 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
|
||||||
@ -1906,9 +1906,12 @@ public class Locations {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void update(Path p) {
|
private void update(Path p) {
|
||||||
if (!isCurrentPlatform(p) && !Files.exists(p.resolve("lib").resolve("jrt-fs.jar")) &&
|
if (!isCurrentPlatform(p)) {
|
||||||
!Files.exists(systemJavaHome.resolve("modules")))
|
var noJavaRuntimeFS = Files.notExists(resolveInJavaHomeLib(p, "jrt-fs.jar"));
|
||||||
|
var noModulesFile = Files.notExists(resolveInJavaHomeLib(p, "modules"));
|
||||||
|
if (noJavaRuntimeFS || noModulesFile)
|
||||||
throw new IllegalArgumentException(p.toString());
|
throw new IllegalArgumentException(p.toString());
|
||||||
|
}
|
||||||
systemJavaHome = p;
|
systemJavaHome = p;
|
||||||
modules = null;
|
modules = null;
|
||||||
}
|
}
|
||||||
@ -1921,6 +1924,10 @@ public class Locations {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static Path resolveInJavaHomeLib(Path javaHomePath, String name) {
|
||||||
|
return javaHomePath.resolve("lib").resolve(name);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
Location getLocationForModule(String name) throws IOException {
|
Location getLocationForModule(String name) throws IOException {
|
||||||
initSystemModules();
|
initSystemModules();
|
||||||
@ -1967,10 +1974,10 @@ public class Locations {
|
|||||||
Collections.singletonMap("java.home", systemJavaHome.toString());
|
Collections.singletonMap("java.home", systemJavaHome.toString());
|
||||||
jrtfs = FileSystems.newFileSystem(jrtURI, attrMap);
|
jrtfs = FileSystems.newFileSystem(jrtURI, attrMap);
|
||||||
} catch (ProviderNotFoundException ex) {
|
} catch (ProviderNotFoundException ex) {
|
||||||
URL javaHomeURL = systemJavaHome.resolve("jrt-fs.jar").toUri().toURL();
|
URL jfsJar = resolveInJavaHomeLib(systemJavaHome, "jrt-fs.jar").toUri().toURL();
|
||||||
ClassLoader currentLoader = Locations.class.getClassLoader();
|
ClassLoader currentLoader = Locations.class.getClassLoader();
|
||||||
URLClassLoader fsLoader =
|
URLClassLoader fsLoader =
|
||||||
new URLClassLoader(new URL[] {javaHomeURL}, currentLoader);
|
new URLClassLoader(new URL[] {jfsJar}, currentLoader);
|
||||||
|
|
||||||
jrtfs = FileSystems.newFileSystem(jrtURI, Collections.emptyMap(), fsLoader);
|
jrtfs = FileSystems.newFileSystem(jrtURI, Collections.emptyMap(), fsLoader);
|
||||||
|
|
||||||
@ -1982,7 +1989,7 @@ public class Locations {
|
|||||||
|
|
||||||
modules = jrtfs.getPath("/modules");
|
modules = jrtfs.getPath("/modules");
|
||||||
} catch (FileSystemNotFoundException | ProviderNotFoundException e) {
|
} catch (FileSystemNotFoundException | ProviderNotFoundException e) {
|
||||||
modules = systemJavaHome.resolve("modules");
|
modules = resolveInJavaHomeLib(systemJavaHome, "modules");
|
||||||
if (!Files.exists(modules))
|
if (!Files.exists(modules))
|
||||||
throw new IOException("can't find system classes", e);
|
throw new IOException("can't find system classes", e);
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2018, 2022, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2018, 2023, 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
|
||||||
@ -23,7 +23,7 @@
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
* @bug 8196433
|
* @bug 8196433 8307168
|
||||||
* @summary use the new error diagnostic approach at javac.Main
|
* @summary use the new error diagnostic approach at javac.Main
|
||||||
* @library /tools/lib
|
* @library /tools/lib
|
||||||
* @modules jdk.compiler/com.sun.tools.javac.api
|
* @modules jdk.compiler/com.sun.tools.javac.api
|
||||||
@ -255,6 +255,34 @@ public class OptionSmokeTest extends TestRunner {
|
|||||||
String.format("--release %s --upgrade-module-path any", Source.DEFAULT.name));
|
String.format("--release %s --upgrade-module-path any", Source.DEFAULT.name));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void consistentSystemOptionHandlingWithAnEmptyDirectory(Path base) throws Exception {
|
||||||
|
tb.createDirectories(base);
|
||||||
|
doTestNoSource(base, "error: illegal argument for --system: %s".formatted(base), String.format("--system %s", base));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void consistentSystemOptionHandlingWithLibJrtFsJar(Path base) throws Exception {
|
||||||
|
tb.createDirectories(base);
|
||||||
|
tb.writeFile(base.resolve("lib").resolve("jrt-fs.jar"), "this is not a JAR file");
|
||||||
|
doTestNoSource(base, "error: illegal argument for --system: %s".formatted(base), String.format("--system %s", base));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void consistentSystemOptionHandlingWithLibModules(Path base) throws Exception {
|
||||||
|
tb.createDirectories(base);
|
||||||
|
tb.writeFile(base.resolve("lib").resolve("modules"), "this is not a modules file");
|
||||||
|
doTestNoSource(base, "error: illegal argument for --system: %s".formatted(base), String.format("--system %s", base));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void consistentSystemOptionHandlingWithAlmostValidLibEntries(Path base) throws Exception {
|
||||||
|
tb.createDirectories(base);
|
||||||
|
tb.writeFile(base.resolve("lib").resolve("jrt-fs.jar"), "this is not a JAR file");
|
||||||
|
tb.writeFile(base.resolve("lib").resolve("modules"), "this is not a modules file");
|
||||||
|
doTestNoSource(base, "error: no source files", String.format("--system %s", base));
|
||||||
|
}
|
||||||
|
|
||||||
void doTest(Path base, String output, String options) throws Exception {
|
void doTest(Path base, String output, String options) throws Exception {
|
||||||
Path src = base.resolve("src");
|
Path src = base.resolve("src");
|
||||||
tb.writeJavaFiles(src, "class Dummy { }");
|
tb.writeJavaFiles(src, "class Dummy { }");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user