HADOOP-18652. Path.suffix raises NullPointerException (#5653). Contributed by Patrick Grandjean.
Reviewed-by: Wei-Chiu Chuang <weichiu@apache.org> Signed-off-by: Ayush Saxena <ayushsaxena@apache.org>
This commit is contained in:
parent
f6770dee47
commit
4627242c44
@ -465,7 +465,12 @@ private Path getParentUtil() {
|
|||||||
* @return a new path with the suffix added
|
* @return a new path with the suffix added
|
||||||
*/
|
*/
|
||||||
public Path suffix(String suffix) {
|
public Path suffix(String suffix) {
|
||||||
return new Path(getParent(), getName()+suffix);
|
Path parent = getParent();
|
||||||
|
if (parent == null) {
|
||||||
|
return new Path("/", getName() + suffix);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Path(parent, getName() + suffix);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -528,4 +528,11 @@ public void testSerDeser() throws Throwable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test(timeout = 30000)
|
||||||
|
public void testSuffixFromRoot() {
|
||||||
|
Path root = new Path("/");
|
||||||
|
Assert.assertNull(root.getParent());
|
||||||
|
Assert.assertEquals(new Path("/bar"), root.suffix("bar"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user