8166675: Latent bug in jar file handling during module path processing
Reviewed-by: jlahoda
This commit is contained in:
parent
d084a21c15
commit
04de18856a
@ -43,6 +43,7 @@ import java.nio.file.InvalidPathException;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.nio.file.ProviderNotFoundException;
|
||||
import java.nio.file.spi.FileSystemProvider;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
@ -1119,8 +1120,12 @@ public class Locations {
|
||||
}
|
||||
|
||||
if (p.getFileName().toString().endsWith(".jar") && fsInfo.exists(p)) {
|
||||
URI uri = URI.create("jar:" + p.toUri());
|
||||
try (FileSystem fs = FileSystems.newFileSystem(uri, fsEnv, null)) {
|
||||
FileSystemProvider jarFSProvider = fsInfo.getJarFSProvider();
|
||||
if (jarFSProvider == null) {
|
||||
log.error(Errors.NoZipfsForArchive(p));
|
||||
return null;
|
||||
}
|
||||
try (FileSystem fs = jarFSProvider.newFileSystem(p, fsEnv)) {
|
||||
Path moduleInfoClass = fs.getPath("module-info.class");
|
||||
if (Files.exists(moduleInfoClass)) {
|
||||
String moduleName = readModuleName(moduleInfoClass);
|
||||
@ -1132,9 +1137,6 @@ public class Locations {
|
||||
} catch (IOException e) {
|
||||
log.error(Errors.LocnCantReadFile(p));
|
||||
return null;
|
||||
} catch (ProviderNotFoundException e) {
|
||||
log.error(Errors.NoZipfsForArchive(p));
|
||||
return null;
|
||||
}
|
||||
|
||||
//automatic module:
|
||||
@ -1177,8 +1179,12 @@ public class Locations {
|
||||
// workaround for now
|
||||
FileSystem fs = fileSystems.get(p);
|
||||
if (fs == null) {
|
||||
URI uri = URI.create("jar:" + p.toUri());
|
||||
fs = FileSystems.newFileSystem(uri, Collections.emptyMap(), null);
|
||||
FileSystemProvider jarFSProvider = fsInfo.getJarFSProvider();
|
||||
if (jarFSProvider == null) {
|
||||
log.error(Errors.LocnCantReadFile(p));
|
||||
return null;
|
||||
}
|
||||
fs = jarFSProvider.newFileSystem(p, Collections.emptyMap());
|
||||
try {
|
||||
Path moduleInfoClass = fs.getPath("classes/module-info.class");
|
||||
String moduleName = readModuleName(moduleInfoClass);
|
||||
@ -1194,7 +1200,7 @@ public class Locations {
|
||||
}
|
||||
} catch (ModuleNameReader.BadClassFile e) {
|
||||
log.error(Errors.LocnBadModuleInfo(p));
|
||||
} catch (IOException | ProviderNotFoundException e) {
|
||||
} catch (IOException e) {
|
||||
log.error(Errors.LocnCantReadFile(p));
|
||||
return null;
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2016, 2017, 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
|
||||
@ -74,6 +74,7 @@ public class LimitedImage {
|
||||
);
|
||||
|
||||
//check proper diagnostics when zip/jar FS not present:
|
||||
System.err.println("Test " + testJar + " on classpath");
|
||||
actualOutput = new JavacTask(tb, Mode.CMDLINE)
|
||||
.classpath(testJar)
|
||||
.options("-XDrawDiagnostics")
|
||||
@ -84,9 +85,10 @@ public class LimitedImage {
|
||||
.getOutputLines(OutputKind.DIRECT);
|
||||
|
||||
if (!expectedOutput.equals(actualOutput)) {
|
||||
throw new AssertionError("Unexpected output: " + actualOutput);
|
||||
throw new AssertionError("Unexpected output");
|
||||
}
|
||||
|
||||
System.err.println("Test " + testJar + " on sourcepath");
|
||||
actualOutput = new JavacTask(tb, Mode.CMDLINE)
|
||||
.sourcepath(testJar)
|
||||
.options("-XDrawDiagnostics")
|
||||
@ -97,9 +99,10 @@ public class LimitedImage {
|
||||
.getOutputLines(OutputKind.DIRECT);
|
||||
|
||||
if (!expectedOutput.equals(actualOutput)) {
|
||||
throw new AssertionError("Unexpected output: " + actualOutput);
|
||||
throw new AssertionError("Unexpected output");
|
||||
}
|
||||
|
||||
System.err.println("Test " + testJar + " on modulepath");
|
||||
actualOutput = new JavacTask(tb, Mode.CMDLINE)
|
||||
.options("-XDrawDiagnostics",
|
||||
"--module-path", testJar.toString())
|
||||
@ -110,7 +113,7 @@ public class LimitedImage {
|
||||
.getOutputLines(OutputKind.DIRECT);
|
||||
|
||||
if (!expectedOutput.equals(actualOutput)) {
|
||||
throw new AssertionError("Unexpected output: " + actualOutput);
|
||||
throw new AssertionError("Unexpected output");
|
||||
}
|
||||
|
||||
expectedOutput = Arrays.asList(
|
||||
@ -118,6 +121,7 @@ public class LimitedImage {
|
||||
"1 error"
|
||||
);
|
||||
|
||||
System.err.println("Test directory containing " + testJar + " on modulepath");
|
||||
actualOutput = new JavacTask(tb, Mode.CMDLINE)
|
||||
.classpath()
|
||||
.options("-XDrawDiagnostics",
|
||||
@ -129,7 +133,7 @@ public class LimitedImage {
|
||||
.getOutputLines(OutputKind.DIRECT);
|
||||
|
||||
if (!expectedOutput.equals(actualOutput)) {
|
||||
throw new AssertionError("Unexpected output: " + actualOutput);
|
||||
throw new AssertionError("Unexpected output");
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user