Skip to content

Commit 2ab4f40

Browse files
committed
Corrected NPE in FileDataWriter.close
1 parent 522fd34 commit 2ab4f40

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

strongback/src/org/strongback/FileDataWriter.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public FileDataWriter(Iterable<DataRecorderChannel> channels, Supplier<String> f
5050
fileSize = numWrites * recordLength + 1024; // add extra room for header and miscellaneous
5151

5252
AtomicInteger count = new AtomicInteger();
53-
channels.forEach(ch->count.incrementAndGet());
53+
channels.forEach(ch -> count.incrementAndGet());
5454
channelCount = count.get() + 1; // adding the time sequence
5555

5656
openIfNeeded();
@@ -87,7 +87,7 @@ protected void openIfNeeded() {
8787
assert name != null;
8888
writer.write(name);
8989
});
90-
} else if ( writer.remaining() < recordLength) {
90+
} else if (writer.remaining() < recordLength) {
9191
System.err.println("Insuffient space to write next all of next record, closing file");
9292
close();
9393
openIfNeeded();
@@ -103,11 +103,13 @@ public void write(long time) {
103103

104104
@Override
105105
public void close() {
106-
try {
107-
writer.close();
108-
} finally {
109-
writer = null;
110-
suppliers.clear();
106+
if (writer != null) {
107+
try {
108+
writer.close();
109+
} finally {
110+
writer = null;
111+
suppliers.clear();
112+
}
111113
}
112114
}
113115

0 commit comments

Comments
 (0)