Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved handling of null values in AbstractEditPartViewer #433

Closed
ptziegler opened this issue Apr 22, 2024 · 2 comments · Fixed by #442
Closed

Improved handling of null values in AbstractEditPartViewer #433

ptziegler opened this issue Apr 22, 2024 · 2 comments · Fixed by #442

Comments

@ptziegler
Copy link
Contributor

This is an error I just encountered while implementing a new graphical viewer:

java.lang.NullPointerException: Cannot invoke "org.eclipse.gef.EditPart.setSelected(int)" because "part" is null
	at org.eclipse.gef.ui.parts.AbstractEditPartViewer.lambda$3(AbstractEditPartViewer.java:499)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
	at org.eclipse.gef.ui.parts.AbstractEditPartViewer.primDeselectAll(AbstractEditPartViewer.java:499)
	at org.eclipse.gef.ui.parts.AbstractEditPartViewer.select(AbstractEditPartViewer.java:634)
	at org.eclipse.wb.internal.core.model.property.table.PropertyTable.setActivePropertyInfo(PropertyTable.java:941)
	at org.eclipse.wb.internal.core.model.property.table.PropertyTable.handleMouseDown(PropertyTable.java:340)
	at org.eclipse.wb.internal.core.model.property.table.PropertyTable$1.mouseDown(PropertyTable.java:174)

Cause seems to be that null is among the selected edit parts. Based on the exception, I assume that this is an unexpected state.
I think the select() method should either ignore those values or all methods working on the selection should have an additional null-check.

@ptziegler ptziegler changed the title Improved handling of null values in AbstractEditPartHandling Improved handling of null values in AbstractEditPartViewer Apr 22, 2024
@azoitl
Copy link
Contributor

azoitl commented Apr 26, 2024

You are right, I also don't think that there should be a null in the list of selected EditParts. A protection should be added. I looked a bit into the code and I think the SelectionManager would be the right place for that.

However while writing this I had a second look. In all methods where you would update the selection with a null EditPart an NPE would allready be thrown there. So this means you must have another location where you modify the selection list of the AbstractViewer. I guess there is little on GEF side we could do. What would be good to have the AbstractViewer's selection list private. But I guess that is a change we can not easily do.

@ptziegler
Copy link
Contributor Author

However while writing this I had a second look. In all methods where you would update the selection with a null EditPart an NPE would allready be thrown there. So this means you must have another location where you modify the selection list of the AbstractViewer.

I already know what the problem is. I called EditPart editPart = findObjectAt(x, y), followed by select(editPart), without checking whether editPart is null.

My point is that the error message is rather cryptic, and I think we should directly check whether the argument is null, when invoking select(EditPart).

ptziegler added a commit to ptziegler/gef-classic that referenced this issue May 13, 2024
The selection inside a GEF viewer is assumed to always be non-null.
Trying to do so silently puts the viewer in an inconsistent state and
only cause an error when the selection is changed again.

To avoid any changes in behavior, this change only adds a log message
but doesn't change the execution flow.

Resolves eclipse#433
ptziegler added a commit to ptziegler/gef-classic that referenced this issue May 13, 2024
The selection inside a GEF viewer is assumed to always be non-null.
Trying to do so puts the viewer in an inconsistent state because the
edit part is added to the internal selection, before an exception is
fired.

To avoid this, we check the editpart and skip it, if it happens to be
null.

Resolves eclipse#433
ptziegler added a commit to ptziegler/gef-classic that referenced this issue May 14, 2024
The selection inside a GEF viewer is assumed to always be non-null. But
because the (implicit) null check is done after the editpart is added to
the internal list, it leaves the viewer in an inconsistent state.

To avoid this, the null check is done earlier, so that the exception is
thrown before the internal model is modified.

Resolves eclipse#433
ptziegler added a commit to ptziegler/gef-classic that referenced this issue May 14, 2024
The selection inside a GEF viewer is assumed to always be non-null. But
because the (implicit) null check is done after the editpart is added to
the internal list, it leaves the viewer in an inconsistent state.

To avoid this, the null check is done earlier, so that the exception is
thrown before the internal model is modified.

Resolves eclipse#433
azoitl pushed a commit that referenced this issue May 21, 2024
The selection inside a GEF viewer is assumed to always be non-null. But
because the (implicit) null check is done after the editpart is added to
the internal list, it leaves the viewer in an inconsistent state.

To avoid this, the null check is done earlier, so that the exception is
thrown before the internal model is modified.

Resolves #433
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants