Skip to content

Commit 5131371

Browse files
committed
Add defensive code for handler & converter plugins
None of the following should throw an exception (checked or otherwise): * Instantiating a plugin. * Calling Typed.supports(...) on a TypedPlugin. * Calling getInputType() or getOutputType() on a Converter. Any exceptions thrown in those scenarios indicate a malfunction. The relevant service layers now log such exceptions and continue.
1 parent 581f981 commit 5131371

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

src/main/java/org/scijava/convert/AbstractConvertService.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,13 @@ public Collection<Class<?>> getCompatibleOutputClasses(final Class<?> source) {
150150
final Set<Class<?>> compatibleClasses = new HashSet<>();
151151

152152
for (final Converter<?, ?> converter : getInstances()) {
153-
addIfMatches(source, converter.getInputType(), converter.getOutputType(), compatibleClasses);
153+
try {
154+
addIfMatches(source, converter.getInputType(), converter.getOutputType(), compatibleClasses);
155+
}
156+
catch (final Throwable t) {
157+
log().error("Malfunctioning converter plugin: " + //
158+
converter.getClass().getName(), t);
159+
}
154160
}
155161

156162
return compatibleClasses;

src/main/java/org/scijava/plugin/HandlerService.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,12 @@ public interface HandlerService<DT, PT extends HandlerPlugin<DT>> extends
5757
*/
5858
default PT getHandler(final DT data) {
5959
for (final PT handler : getInstances()) {
60-
if (handler.supports(data)) return handler;
60+
try {
61+
if (handler.supports(data)) return handler;
62+
}
63+
catch (final Throwable t) {
64+
log().error("Malfunctioning plugin: " + handler.getClass().getName(), t);
65+
}
6166
}
6267
return null;
6368
}

src/main/java/org/scijava/plugin/TypedService.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,13 @@ public interface TypedService<DT, PT extends TypedPlugin<DT>> extends
6868
*/
6969
default PT find(final DT data) {
7070
for (final PluginInfo<PT> plugin : getPlugins()) {
71-
final PT instance = pluginService().createInstance(plugin);
72-
if (instance != null && instance.supports(data)) return instance;
71+
try {
72+
final PT instance = pluginService().createInstance(plugin);
73+
if (instance != null && instance.supports(data)) return instance;
74+
}
75+
catch (final Throwable t) {
76+
log().error("Malfunctioning plugin: " + plugin.getClassName(), t);
77+
}
7378
}
7479
return null;
7580
}

0 commit comments

Comments
 (0)