[spotbugs] Fix potential NPE in FileBasedConfigTest
Path#getParent can return null. Fix the warning by implementing a helper method which asserts the parent is not null. Change-Id: Ib4f8dff0674b74bc891f15f08bd9755c5ea728dc Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
This commit is contained in:
parent
3705ac5839
commit
b1d8e8642f
|
@ -13,6 +13,7 @@
|
|||
import static org.eclipse.jgit.util.FileUtils.pathToString;
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
|
@ -178,7 +179,7 @@ public void testIncludeRelativeDotDot()
|
|||
final Path includedFile = createFile(CONTENT1.getBytes(UTF_8), "dir1");
|
||||
final ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||
bos.write("[include]\npath=".getBytes(UTF_8));
|
||||
bos.write(("../" + includedFile.getParent().getFileName() + "/"
|
||||
bos.write(("../" + parent(includedFile).getFileName() + "/"
|
||||
+ includedFile.getFileName()).getBytes(UTF_8));
|
||||
|
||||
final Path file = createFile(bos.toByteArray(), "dir2");
|
||||
|
@ -213,7 +214,7 @@ public void testIncludeWithTilde()
|
|||
|
||||
final Path file = createFile(bos.toByteArray(), "repo");
|
||||
final FS fs = FS.DETECTED.newInstance();
|
||||
fs.setUserHome(includedFile.getParent().toFile());
|
||||
fs.setUserHome(parent(includedFile).toFile());
|
||||
|
||||
final FileBasedConfig config = new FileBasedConfig(file.toFile(), fs);
|
||||
config.load();
|
||||
|
@ -231,7 +232,7 @@ public void testIncludeDontInlineIncludedLinesOnSave()
|
|||
FileBasedConfig config = new FileBasedConfig(file.toFile(),
|
||||
FS.DETECTED);
|
||||
config.setString("include", null, "path",
|
||||
("../" + includedFile.getParent().getFileName() + "/"
|
||||
("../" + parent(includedFile).getFileName() + "/"
|
||||
+ includedFile.getFileName()));
|
||||
|
||||
// just by setting the include.path, it won't be included
|
||||
|
@ -280,4 +281,10 @@ private Path createFile(byte[] content, String subdir) throws IOException {
|
|||
}
|
||||
return f;
|
||||
}
|
||||
|
||||
private Path parent(Path file) {
|
||||
Path parent = file.getParent();
|
||||
assertNotNull(parent);
|
||||
return parent;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue