Skip to content
Permalink
Browse files
8266291: (jrtfs) Calling Files.exists may break the JRT filesystem
Reviewed-by: redestad, alanb
  • Loading branch information
sundararajana committed May 14, 2021
1 parent ebcf399 commit af4cd04c2e393f8d1ffef60f49e3269adee649b8
Showing with 35 additions and 4 deletions.
  1. +13 −0 src/java.base/share/classes/jdk/internal/jimage/ImageReader.java
  2. +22 −4 test/jdk/jdk/internal/jrtfs/Basic.java
@@ -468,6 +468,19 @@ Node handleModulesSubTree(String name, ImageLocation loc) {

Node handleResource(String name) {
Node n = null;
if (!name.startsWith("/modules/")) {
return null;
}
// Make sure that the thing that follows "/modules/" is a module name.
int moduleEndIndex = name.indexOf('/', "/modules/".length());
if (moduleEndIndex == -1) {
return null;
}
ImageLocation moduleLoc = findLocation(name.substring(0, moduleEndIndex));
if (moduleLoc == null || moduleLoc.getModuleOffset() == 0) {
return null;
}

String locationPath = name.substring("/modules".length());
ImageLocation resourceLoc = findLocation(locationPath);
if (resourceLoc != null) {
@@ -244,22 +244,30 @@ public void testKnownDirectories(String path, boolean theDefault) throws Excepti
}
}

@DataProvider(name = "topLevelPkgDirs")
private Object[][] topLevelPkgDirs() {
@DataProvider(name = "topLevelNonExistingDirs")
private Object[][] topLevelNonExistingDirs() {
return new Object[][] {
{ "/java/lang" },
{ "java/lang" },
{ "/java/util" },
{ "java/util" },
{ "/modules/modules" },
{ "/modules/modules/" },
{ "/modules/modules/java.base" },
{ "/modules/modules/java.base/" },
{ "/modules/modules/java.base/java/lang/Object.class" },
{ "/modules/modules/javax.scripting" },
{ "/modules/modules/javax.scripting/" },
{ "/modules/modules/javax.scripting/javax/script/ScriptEngine.class" },
};
}

@Test(dataProvider = "topLevelPkgDirs")
@Test(dataProvider = "topLevelNonExistingDirs")
public void testNotExists(String path) throws Exception {
FileSystem fs = FileSystems.getFileSystem(URI.create("jrt:/"));
Path dir = fs.getPath(path);

// package directories should not be there at top level
// These directories should not be there at top level
assertTrue(Files.notExists(dir));
}

@@ -756,5 +764,15 @@ public void objectClassSizeTest() throws Exception {

assertTrue(Files.size(classFile) > 0L);
}

// @bug 8266291: (jrtfs) Calling Files.exists may break the JRT filesystem
@Test
public void fileExistsCallBreaksFileSystem() throws Exception {
Path p = FileSystems.getFileSystem(URI.create("jrt:/")).getPath("modules");
boolean wasDirectory = Files.isDirectory(p);
Path m = p.resolve("modules");
Files.exists(m);
assertTrue(wasDirectory == Files.isDirectory(p));
}
}

0 comments on commit af4cd04

Please sign in to comment.