Skip to content

Commit 5d65b3e

Browse files
committed
Make WrapperService#create not throw exceptions
Instead, let's just return null, since null can only mean one thing: no suitable wrapper was found. This commit also makes the appropriate changes downstream to adjust for the update in behavior.
1 parent 443550d commit 5d65b3e

File tree

5 files changed

+10
-28
lines changed

5 files changed

+10
-28
lines changed

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,7 @@ public abstract class AbstractWrapperService<DT, PT extends WrapperPlugin<DT>>
5252
@Override
5353
public <D extends DT> PT create(final D data) {
5454
final PT instance = findWrapper(data);
55-
if (instance == null) {
56-
throw new IllegalArgumentException("No compatible " +
57-
getPluginType().getSimpleName() + " for data object: " + data);
58-
}
59-
instance.set(data);
55+
if (instance != null) instance.set(data);
6056
return instance;
6157
}
6258

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ public interface WrapperService<DT, PT extends WrapperPlugin<DT>> extends
5959
/**
6060
* Creates a new plugin instance wrapping the given associated data object.
6161
*
62-
* @throws IllegalArgumentException if the data is not compatible with any
63-
* available plugin.
62+
* @return An appropriate plugin instance, or null if the data is not
63+
* compatible with any available plugin.
6464
*/
6565
<D extends DT> PT create(D data);
6666

src/main/java/org/scijava/widget/AbstractInputHarvester.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636

3737
import org.scijava.AbstractContextual;
3838
import org.scijava.convert.ConvertService;
39+
import org.scijava.log.LogService;
3940
import org.scijava.module.Module;
4041
import org.scijava.module.ModuleCanceledException;
4142
import org.scijava.module.ModuleException;
@@ -58,6 +59,9 @@ public abstract class AbstractInputHarvester<P, W> extends AbstractContextual
5859
implements InputHarvester<P, W>
5960
{
6061

62+
@Parameter
63+
private LogService log;
64+
6165
@Parameter
6266
private WidgetService widgetService;
6367

@@ -130,6 +134,9 @@ private <T> WidgetModel addInput(final InputPanel<P, W> inputPanel,
130134

131135
final Class<W> widgetType = inputPanel.getWidgetComponentType();
132136
final InputWidget<?, ?> widget = widgetService.create(model);
137+
if (widget == null) {
138+
log.warn("No widget found for input: " + model.getItem().getName());
139+
}
133140
if (widget != null && widget.getComponentType() == widgetType) {
134141
@SuppressWarnings("unchecked")
135142
final InputWidget<?, W> typedWidget = (InputWidget<?, W>) widget;

src/main/java/org/scijava/widget/DefaultWidgetService.java

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
import org.scijava.plugin.AbstractWrapperService;
4040
import org.scijava.plugin.Parameter;
4141
import org.scijava.plugin.Plugin;
42-
import org.scijava.plugin.PluginInfo;
4342
import org.scijava.service.Service;
4443

4544
/**
@@ -66,22 +65,6 @@ public WidgetModel createModel(InputPanel<?, ?> inputPanel, Module module,
6665
objectPool);
6766
}
6867

69-
// -- WrapperService methods --
70-
71-
@Override
72-
public InputWidget<?, ?> create(final WidgetModel model) {
73-
for (final PluginInfo<InputWidget<?, ?>> info : getPlugins()) {
74-
final InputWidget<?, ?> widget = getPluginService().createInstance(info);
75-
if (widget == null) continue;
76-
if (widget.supports(model)) {
77-
widget.set(model);
78-
return widget;
79-
}
80-
}
81-
log.warn("No widget found for input: " + model.getItem().getName());
82-
return null;
83-
}
84-
8568
// -- PTService methods --
8669

8770
@Override

src/main/java/org/scijava/widget/WidgetService.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,6 @@ public interface WidgetService extends
5151

5252
// -- WrapperService methods --
5353

54-
/** Creates a widget that represents the given widget model. */
55-
@Override
56-
InputWidget<?, ?> create(WidgetModel model);
57-
5854
/**
5955
* Create a {@link WidgetModel} for the given module input.
6056
*

0 commit comments

Comments
 (0)