]> source.dussan.org Git - jgit.git/commitdiff
[spotbugs] Fix potential NPE in FS#write 70/173370/5
authorMatthias Sohn <matthias.sohn@sap.com>
Fri, 4 Dec 2020 08:40:47 +0000 (09:40 +0100)
committerChristian Halstrick <christian.halstrick@sap.com>
Thu, 17 Dec 2020 17:42:00 +0000 (18:42 +0100)
Path#getParent can return null.

Change-Id: I01f13ac426dda4c007cc5caab546a0c9be62ce76
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
org.eclipse.jgit/src/org/eclipse/jgit/util/FS.java

index d8cab358e75452b0d0ab0fe14445e017dc14cbdf..874bfe87353f8ada301dbbe67fb4c248c41358d1 100644 (file)
@@ -511,7 +511,10 @@ public abstract class FS {
                }
 
                private static void write(Path p, String body) throws IOException {
-                       FileUtils.mkdirs(p.getParent().toFile(), true);
+                       Path parent = p.getParent();
+                       if (parent != null) {
+                               FileUtils.mkdirs(parent.toFile(), true);
+                       }
                        try (Writer w = new OutputStreamWriter(Files.newOutputStream(p),
                                        UTF_8)) {
                                w.write(body);