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

8263940: NPE when creating default file system when default file system provider is packaged as JAR file on class path #5103

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -33,7 +33,6 @@
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.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 boolean equals(Object obj) {
}
}
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
Copy link
Contributor

@AlanBateman AlanBateman Aug 13, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for correcting the @bug tag.

* @modules jdk.jartool
* @library /test/lib
* @build SetDefaultProvider TestProvider m/* jdk.test.lib.process.ProcessTools
@@ -37,11 +37,14 @@
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 void testClassPath() throws Exception {
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";
Copy link
Contributor

@AlanBateman AlanBateman Aug 13, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This ends up with two copies of TestFIleSystemProvider on the class path. I think we should compile TestProvider to a different directory. That will eliminate the need to filter the classes when creating the JAR file.

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 {

Copy link
Contributor

@AlanBateman AlanBateman Aug 13, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this test, the supporting methods are at the end of the source file, probably should keep it consistent.

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.