mirror of
https://github.com/openjdk/jdk.git
synced 2026-02-05 07:58:40 +00:00
8361587: AssertionError in File.listFiles() when path is empty and -esa is enabled
Reviewed-by: alanb
This commit is contained in:
parent
401af27b9d
commit
eefbfdce31
@ -1134,8 +1134,14 @@ public class File
|
||||
if (ss == null) return null;
|
||||
int n = ss.length;
|
||||
File[] fs = new File[n];
|
||||
for (int i = 0; i < n; i++) {
|
||||
fs[i] = new File(ss[i], this);
|
||||
if (path.isEmpty()) {
|
||||
for (int i = 0; i < n; i++) {
|
||||
fs[i] = new File(ss[i]);
|
||||
}
|
||||
} else {
|
||||
for (int i = 0; i < n; i++) {
|
||||
fs[i] = new File(ss[i], this);
|
||||
}
|
||||
}
|
||||
return fs;
|
||||
}
|
||||
|
||||
@ -22,7 +22,7 @@
|
||||
*/
|
||||
|
||||
/* @test
|
||||
* @bug 4842706 8024695
|
||||
* @bug 4842706 8024695 8361587
|
||||
* @summary Test some file operations with empty path
|
||||
* @run junit EmptyPath
|
||||
*/
|
||||
@ -36,13 +36,14 @@ import java.nio.file.FileStore;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.junit.jupiter.api.condition.DisabledOnOs;
|
||||
import org.junit.jupiter.api.condition.EnabledOnOs;
|
||||
import org.junit.jupiter.api.condition.OS;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
@ -105,6 +106,11 @@ public class EmptyPath {
|
||||
assertTrue(f.exists());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAbsoluteFile() {
|
||||
assertEquals(p.toAbsolutePath().toFile(), f.getAbsoluteFile());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAbsolutePath() {
|
||||
System.out.println(p.toAbsolutePath().toString() + "\n" +
|
||||
@ -112,6 +118,16 @@ public class EmptyPath {
|
||||
assertEquals(p.toAbsolutePath().toString(), f.getAbsolutePath());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getCanonicalFile() throws IOException {
|
||||
assertEquals(p.toRealPath().toFile(), f.getCanonicalFile());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getCanonicalPath() throws IOException {
|
||||
assertEquals(p.toRealPath().toString(), f.getCanonicalPath());
|
||||
}
|
||||
|
||||
private void checkSpace(long expected, long actual) {
|
||||
if (expected == 0) {
|
||||
assertEquals(0L, actual);
|
||||
@ -136,6 +152,11 @@ public class EmptyPath {
|
||||
assertNull(f.getParent());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getParentFile() {
|
||||
assertNull(f.getParentFile());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getPath() {
|
||||
assertEquals(p.toString(), f.getPath());
|
||||
@ -198,11 +219,57 @@ public class EmptyPath {
|
||||
assertEquals(nioSet, ioSet);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void listFiles() throws IOException {
|
||||
File child = new File(f.getAbsoluteFile(), "child");
|
||||
assertTrue(child.createNewFile());
|
||||
child.deleteOnExit();
|
||||
|
||||
File[] files = f.listFiles();
|
||||
for (File file : files)
|
||||
assertEquals(-1, f.toString().indexOf(File.separatorChar));
|
||||
|
||||
Set<String> ioSet = Arrays.stream(files)
|
||||
.map(File::getName)
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
assertTrue(ioSet.contains(child.getName()));
|
||||
|
||||
Set<String> nioSet = Files.list(p)
|
||||
.map(Path::getFileName)
|
||||
.map(Path::toString)
|
||||
.collect(Collectors.toSet());
|
||||
assertEquals(nioSet, ioSet);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void listRoots() {
|
||||
Set<String> expected = Arrays.stream(f.getAbsoluteFile().listRoots())
|
||||
.map(File::toString)
|
||||
.collect(Collectors.toSet());
|
||||
Set<String> actual = Arrays.stream(f.listRoots())
|
||||
.map(File::toString)
|
||||
.collect(Collectors.toSet());
|
||||
assertEquals(expected, actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mkdir() {
|
||||
assertFalse(f.mkdir());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mkdirs() {
|
||||
assertFalse(f.mkdirs());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void renameTo() throws IOException {
|
||||
File tmp = File.createTempFile("foo", "bar", f.getAbsoluteFile());
|
||||
assertTrue(tmp.exists());
|
||||
assertFalse(f.renameTo(tmp));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setLastModified() {
|
||||
long t0 = f.lastModified();
|
||||
@ -271,6 +338,12 @@ public class EmptyPath {
|
||||
assertEquals(p, f.toPath());
|
||||
}
|
||||
|
||||
@Test
|
||||
public String toString() {
|
||||
assertEquals(EMPTY_STRING, f.toString());
|
||||
return EMPTY_STRING;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void toURI() {
|
||||
assertEquals(f.toPath().toUri(), f.toURI());
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user