8263940: NPE when creating default file system when default file system provider is packaged as JAR file on class path
Reviewed-by: naoto, bpb, iris, joehw
This commit is contained in:
parent
d06d0b9e9d
commit
717792c3b7
@ -33,7 +33,6 @@ import java.io.File;
|
||||
import java.io.RandomAccessFile;
|
||||
import java.io.UncheckedIOException;
|
||||
import java.lang.ref.Cleaner.Cleanable;
|
||||
import java.nio.charset.CharacterCodingException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.file.InvalidPathException;
|
||||
import java.nio.file.attribute.BasicFileAttributes;
|
||||
@ -69,6 +68,7 @@ import jdk.internal.perf.PerfCounter;
|
||||
import jdk.internal.ref.CleanerFactory;
|
||||
import jdk.internal.vm.annotation.Stable;
|
||||
import sun.nio.cs.UTF_8;
|
||||
import sun.nio.fs.DefaultFileSystemProvider;
|
||||
import sun.security.util.SignatureFileVerifier;
|
||||
|
||||
import static java.util.zip.ZipConstants64.*;
|
||||
@ -1255,14 +1255,19 @@ public class ZipFile implements ZipConstants, Closeable {
|
||||
}
|
||||
}
|
||||
private static final HashMap<Key, Source> files = new HashMap<>();
|
||||
|
||||
/**
|
||||
* Use the platform's default file system to avoid
|
||||
* issues when the VM is configured to use a custom file system provider.
|
||||
*/
|
||||
private static final java.nio.file.FileSystem builtInFS =
|
||||
DefaultFileSystemProvider.theFileSystem();
|
||||
|
||||
static Source get(File file, boolean toDelete, ZipCoder zc) throws IOException {
|
||||
final Key key;
|
||||
try {
|
||||
key = new Key(file,
|
||||
Files.readAttributes(file.toPath(), BasicFileAttributes.class),
|
||||
zc);
|
||||
Files.readAttributes(builtInFS.getPath(file.getPath()),
|
||||
BasicFileAttributes.class), zc);
|
||||
} catch (InvalidPathException ipe) {
|
||||
throw new IOException(ipe);
|
||||
}
|
||||
|
@ -23,7 +23,7 @@
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @bug 8266345
|
||||
* @bug 4313887 7006126 8142968 8178380 8183320 8210112 8266345 8263940
|
||||
* @modules jdk.jartool
|
||||
* @library /test/lib
|
||||
* @build SetDefaultProvider TestProvider m/* jdk.test.lib.process.ProcessTools
|
||||
@ -37,11 +37,14 @@ import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.spi.ToolProvider;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import jdk.test.lib.process.ProcessTools;
|
||||
|
||||
import org.testng.annotations.BeforeTest;
|
||||
import org.testng.annotations.Test;
|
||||
import static org.testng.Assert.*;
|
||||
|
||||
@ -73,6 +76,45 @@ public class SetDefaultProvider {
|
||||
assertTrue(exitValue == 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test override of default FileSystemProvider with a
|
||||
* FileSystemProvider jar and the main application on the class path.
|
||||
*/
|
||||
public void testClassPathWithFileSystemProviderJar() throws Exception {
|
||||
String testClasses = System.getProperty("test.classes");
|
||||
Path jar = Path.of("testFileSystemProvider.jar");
|
||||
Files.deleteIfExists(jar);
|
||||
createFileSystemProviderJar(jar, Path.of(testClasses));
|
||||
String classpath = jar + File.pathSeparator + testClasses
|
||||
+ File.separator + "modules" + File.separator + "m";
|
||||
int exitValue = exec(SET_DEFAULT_FSP, "-cp", classpath, "p.Main");
|
||||
assertTrue(exitValue == 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a JAR containing the FileSystemProvider used to override the
|
||||
* default FileSystemProvider
|
||||
*/
|
||||
private void createFileSystemProviderJar(Path jar, Path dir) throws IOException {
|
||||
|
||||
List<String> args = new ArrayList<>();
|
||||
args.add("--create");
|
||||
args.add("--file=" + jar);
|
||||
try (Stream<Path> stream = Files.list(dir)) {
|
||||
List<String> paths = stream
|
||||
.map(path -> path.getFileName().toString())
|
||||
.filter(f -> f.startsWith("TestProvider"))
|
||||
.toList();
|
||||
for(var p : paths) {
|
||||
args.add("-C");
|
||||
args.add(dir.toString());
|
||||
args.add(p);
|
||||
}
|
||||
}
|
||||
int ret = JAR_TOOL.run(System.out, System.out, args.toArray(new String[0]));
|
||||
assertTrue(ret == 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test override of default FileSystemProvider with the main application
|
||||
* on the class path and a SecurityManager enabled.
|
||||
|
Loading…
x
Reference in New Issue
Block a user