mirror of
https://github.com/openjdk/jdk.git
synced 2026-02-19 23:05:28 +00:00
8326487: ZipFileSystem.getPath("").getFileName() returns null instead of an empty Path
Reviewed-by: alanb, lancea
This commit is contained in:
parent
c8338be9ad
commit
c594da7304
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2009, 2023, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2009, 2026, 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
|
||||
@ -55,6 +55,8 @@ import static java.nio.file.StandardOpenOption.WRITE;
|
||||
*/
|
||||
final class ZipPath implements Path {
|
||||
|
||||
private static final byte[] EMPTY_PATH = new byte[0];
|
||||
|
||||
private final ZipFileSystem zfs;
|
||||
private final byte[] path;
|
||||
private volatile int[] offsets;
|
||||
@ -93,8 +95,15 @@ final class ZipPath implements Path {
|
||||
@Override
|
||||
public ZipPath getFileName() {
|
||||
int off = path.length;
|
||||
if (off == 0 || off == 1 && path[0] == '/')
|
||||
if (off == 0) {
|
||||
// empty path, which is defined as consisting solely of
|
||||
// one name element that is empty
|
||||
return new ZipPath(getFileSystem(), EMPTY_PATH, true);
|
||||
}
|
||||
if (off == 1 && path[0] == '/') {
|
||||
// root path, which is defined as having 0 name elements
|
||||
return null;
|
||||
}
|
||||
while (--off >= 0 && path[off] != '/') {}
|
||||
if (off < 0)
|
||||
return this;
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2009, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2009, 2026, 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
|
||||
@ -30,10 +30,10 @@ import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.nio.file.ProviderMismatchException;
|
||||
|
||||
/**
|
||||
/*
|
||||
*
|
||||
* @test
|
||||
* @bug 8038500 8040059 8139956 8146754 8172921 8186142
|
||||
* @bug 8038500 8040059 8139956 8146754 8172921 8186142 8326487
|
||||
* @summary Tests path operations for zip provider.
|
||||
*
|
||||
* @modules jdk.zipfs
|
||||
@ -92,6 +92,10 @@ public class PathOps {
|
||||
check(result, Boolean.toString(expected));
|
||||
}
|
||||
|
||||
void check(Object result, int expected) {
|
||||
check(result, Integer.toString(expected));
|
||||
}
|
||||
|
||||
PathOps root(String expected) {
|
||||
out.println("check root");
|
||||
checkPath();
|
||||
@ -113,6 +117,13 @@ public class PathOps {
|
||||
return this;
|
||||
}
|
||||
|
||||
PathOps nameCount(int expected) {
|
||||
out.println("check nameCount");
|
||||
checkPath();
|
||||
check(path.getNameCount(), expected);
|
||||
return this;
|
||||
}
|
||||
|
||||
PathOps element(int index, String expected) {
|
||||
out.format("check element %d\n", index);
|
||||
checkPath();
|
||||
@ -284,7 +295,15 @@ public class PathOps {
|
||||
test("/")
|
||||
.root("/")
|
||||
.parent(null)
|
||||
.name(null);
|
||||
.name(null)
|
||||
.nameCount(0);
|
||||
|
||||
// empty name
|
||||
test("")
|
||||
.root(null)
|
||||
.parent(null)
|
||||
.name("")
|
||||
.nameCount(1);
|
||||
|
||||
// no root component
|
||||
test("a/b")
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user