Skip to content

Commit 6b855f3

Browse files
committed
AbstractInputHarvester: fix unsafe widget cast
We now explicitly check if the widget is the right type before using it. In practice, the AbstractInputPanel#supports(InputWidget) method already checked this, so it should never be the case that an incompatible widget is returned by WidgetService#create(WidgetModel). But there is no guarantee that all downstream code is using the abstract superclasses, so let's check again -- better safe than sorry here.
1 parent 780411e commit 6b855f3

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,9 @@ private <T> WidgetModel addInput(final InputPanel<P, W> inputPanel,
124124
final WidgetModel model =
125125
new WidgetModel(getContext(), inputPanel, module, item, getObjects(type));
126126

127+
final Class<W> widgetType = inputPanel.getWidgetComponentType();
127128
final InputWidget<?, ?> widget = widgetService.create(model);
128-
if (widget != null) {
129-
// FIXME: This cast is NOT safe! Multiple UIs in the
130-
// classpath will have clashing widget implementations.
129+
if (widget != null && widget.getComponentType() == widgetType) {
131130
@SuppressWarnings("unchecked")
132131
final InputWidget<?, W> typedWidget = (InputWidget<?, W>) widget;
133132
inputPanel.addWidget(typedWidget);

0 commit comments

Comments
 (0)