diff options
author | Matthias Sohn <matthias.sohn@sap.com> | 2020-12-03 01:54:25 +0100 |
---|---|---|
committer | Christian Halstrick <christian.halstrick@sap.com> | 2020-12-17 18:42:00 +0100 |
commit | b1d8e8642f1143edc1141f1ce00e39a5b95f0b6d (patch) | |
tree | 08d293dbc2d2880a93d93fc737ef78af75b07974 | |
parent | 3705ac58391f979d2a7b6689dd96d6531e975c53 (diff) | |
download | jgit-b1d8e8642f1143edc1141f1ce00e39a5b95f0b6d.tar.gz jgit-b1d8e8642f1143edc1141f1ce00e39a5b95f0b6d.zip |
[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>
-rw-r--r-- | org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/FileBasedConfigTest.java | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/FileBasedConfigTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/FileBasedConfigTest.java index 803ff108f8..b8b503cdcd 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/FileBasedConfigTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/FileBasedConfigTest.java @@ -13,6 +13,7 @@ import static java.nio.charset.StandardCharsets.UTF_8; 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 class FileBasedConfigTest { 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 class FileBasedConfigTest { 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 class FileBasedConfigTest { 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 @@ public class FileBasedConfigTest { } return f; } + + private Path parent(Path file) { + Path parent = file.getParent(); + assertNotNull(parent); + return parent; + } } |