[spotbugs] Fix potential NPE in FS#write

Path#getParent can return null.

Change-Id: I01f13ac426dda4c007cc5caab546a0c9be62ce76
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
This commit is contained in:
Matthias Sohn 2020-12-04 09:40:47 +01:00 committed by Christian Halstrick
parent 1ed6353962
commit 23bc9dc71d
1 changed files with 4 additions and 1 deletions

View File

@ -511,7 +511,10 @@ private static Duration measureMinimalRacyInterval(Path dir) {
}
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);