Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8346768: [CRaC] Ignore errors parsing classpath #168

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,14 @@ public abstract class JDKFileResource extends JDKFdResource {
.split(File.pathSeparator);
CLASSPATH_ENTRIES = new Path[items.length];
for (int i = 0; i < items.length; i++) {
// On Windows, path with forward slashes starting with '/' is an accepted classpath
// element, even though it might seem as invalid and parsing in Path.of(...) would fail.
CLASSPATH_ENTRIES[i] = new File(items[i]).toPath();
try {
// On Windows, path with forward slashes starting with '/' is an accepted classpath
// element, even though it might seem as invalid and parsing in Path.of(...) would fail.
CLASSPATH_ENTRIES[i] = new File(items[i]).toPath();
} catch (Exception e) {
// Ignore any exception parsing the path: URLClassPath.toFileURL() ignores IOExceptions
// as well, here we might get InvalidPathException
}
}
}

Expand Down Expand Up @@ -56,7 +61,7 @@ protected boolean matchClasspath(String path) {
Path p = Path.of(path);
for (Path entry : CLASSPATH_ENTRIES) {
try {
if (Files.isSameFile(p, entry)) {
if (entry != null && Files.isSameFile(p, entry)) {
return true;
}
} catch (IOException e) {
Expand Down
49 changes: 36 additions & 13 deletions test/jdk/jdk/crac/fileDescriptors/ClasspathParseTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,31 +21,54 @@
* questions.
*/

import jdk.crac.Core;
import jdk.test.lib.Utils;
import jdk.test.lib.crac.CracBuilder;
import jdk.test.lib.crac.CracEngine;
import jdk.test.lib.crac.CracTest;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Arrays;

import static jdk.test.lib.Asserts.assertEquals;

/**
* @test
* @library /test/lib
* @run driver ClasspathParseTest
* @modules java.base/jdk.internal.crac:+open
* @build ClasspathParseTest
* @run driver jdk.test.lib.crac.CracTest
*/
public class ClasspathParseTest {
public class ClasspathParseTest implements CracTest {
public static final String JAVA = Utils.TEST_JDK + "/bin/java";

public static void main(String[] args) throws IOException, InterruptedException {
if (args.length == 0) {
String classpath = ClasspathParseTest.class.getProtectionDomain().getCodeSource().getLocation().getPath();
int exit = new ProcessBuilder().command(JAVA, "-cp", classpath, ClasspathParseTest.class.getName(), "ignored")
.inheritIO().start().waitFor();
assertEquals(0, exit);
} else {
// assert that code source path started with "/" as we expect (even on Windows)
if (!System.getProperty("java.class.path").startsWith("/")) {
System.exit(2);
}
@Override
public void test() throws Exception {
String someJar = Arrays.stream(System.getProperty("java.class.path").split(File.pathSeparator))
.filter(f -> f.endsWith(".jar")).findAny()
.orElseThrow(() -> new AssertionError("there should be some jar on classpath"));
new CracBuilder()
.engine(CracEngine.SIMULATE)
.printResources(true)
.classpathEntry(ClasspathParseTest.class.getProtectionDomain().getCodeSource().getLocation().getPath())
.classpathEntry("file:/C:\\some\\invalid/path")
.classpathEntry(someJar)
.startCheckpoint().waitForSuccess();
}

@Override
public void exec() throws Exception {
// assert that code source path started with "/" as we expect (even on Windows)
String cp = System.getProperty("java.class.path");
if (!cp.startsWith("/")) {
System.exit(2);
}
String someJar = Arrays.stream(cp.split(File.pathSeparator)).filter(f -> f.endsWith(".jar")).findAny()
.orElseThrow(() -> new AssertionError("jar file should be provided on classpath"));
try (var fis = new FileInputStream(someJar)) {
Core.checkpointRestore();
}
}
}