Skip to content

Commit 0dc42f7

Browse files
committed
DefaultIOService: defensive checks for IOPlugins
If an opener or saver was not found for a given source, we would get NPEs. Let's protect against that by checking to see if we got a valid opener/saver.
1 parent 3895f2d commit 0dc42f7

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/main/java/org/scijava/io/DefaultIOService.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,16 +82,25 @@ public <D> IOPlugin<D> getSaver(final D data, final String destination) {
8282

8383
@Override
8484
public Object open(final String source) throws IOException {
85-
final Object data = getOpener(source).open(source);
86-
eventService.publish(new DataOpenedEvent(source, data));
85+
IOPlugin<?> opener = getOpener(source);
86+
Object data = null;
87+
if (opener != null) {
88+
data= opener.open(source);
89+
}
90+
if (data != null) {
91+
eventService.publish(new DataOpenedEvent(source, data));
92+
}
8793
return data;
8894
}
8995

9096
@Override
9197
public void save(final Object data, final String destination)
9298
throws IOException
9399
{
94-
getSaver(data, destination).save(data, destination);
100+
IOPlugin<Object> saver = getSaver(data, destination);
101+
if (saver != null) {
102+
saver.save(data, destination);
103+
}
95104
eventService.publish(new DataSavedEvent(destination, data));
96105
}
97106

0 commit comments

Comments
 (0)