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

Logged NPE in ViewerUpdateMonitor constructor #1500

Open
mx990 opened this issue Aug 13, 2024 · 1 comment · May be fixed by #1508
Open

Logged NPE in ViewerUpdateMonitor constructor #1500

mx990 opened this issue Aug 13, 2024 · 1 comment · May be fixed by #1508
Labels
bug Something isn't working

Comments

@mx990
Copy link

mx990 commented Aug 13, 2024

There is a logged NPE due to viewerInput being null in the constructor of ViewerUpdateMonitor when updating tree elements during Viewer.setInput(null):

public ViewerUpdateMonitor(TreeModelContentProvider contentProvider, Object viewerInput, TreePath elementPath, Object element, IElementContentProvider elementContentProvider, IPresentationContext context) {
fContext = context;
// Bug 380288: Catch and log a race condition where the viewer input is null.
if (viewerInput == null) {
DebugUIPlugin.log(new NullPointerException("Input to viewer update should not be null")); //$NON-NLS-1$
}

The problem originally occurred when watching a variable from the Variables view using right click->Watch, which switches from the Variables view to the Expressions view. However, I was able to reproduce the problem on master with several of the tests in org.eclipse.debug.tests.

Steps to reproduce

I expected: neither logged exception nor hit at breakpoint

But got: logged exceptions and multiple hits at breakpoint

Here is some relevant log output

From <workspace>/.metadata/.log

!ENTRY org.eclipse.debug.ui 4 120 2024-08-13 14:55:12.260
!MESSAGE Error logged from Debug UI: 
!STACK 0
java.lang.NullPointerException: Input to viewer update should not be null
	at org.eclipse.debug.internal.ui.viewers.model.ViewerUpdateMonitor.<init>(ViewerUpdateMonitor.java:90)
	at org.eclipse.debug.internal.ui.viewers.model.ChildrenUpdate.<init>(ChildrenUpdate.java:45)
	at org.eclipse.debug.internal.ui.viewers.model.TreeModelContentProvider.doUpdateElement(TreeModelContentProvider.java:1190)
	at org.eclipse.debug.internal.ui.viewers.model.TreeModelContentProvider.updateElement(TreeModelContentProvider.java:1762)
	at org.eclipse.jface.viewers.TreeViewer.virtualLazyUpdateWidget(TreeViewer.java:1001)
	at org.eclipse.jface.viewers.TreeViewer.lambda$1(TreeViewer.java:260)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:91)
	at org.eclipse.swt.widgets.Display.sendEvent(Display.java:5855)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1617)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1643)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1626)
	at org.eclipse.swt.widgets.Tree.checkData(Tree.java:372)
	at org.eclipse.swt.widgets.Tree.cellDataProc(Tree.java:304)
	at org.eclipse.swt.widgets.Display.cellDataProc(Display.java:995)
	at org.eclipse.swt.internal.gtk.GTK.gtk_tree_view_column_cell_set_cell_data(Native Method)
	at org.eclipse.swt.widgets.Tree.calculateWidth(Tree.java:443)
	at org.eclipse.swt.widgets.Tree.calculateWidth(Tree.java:518)
	at org.eclipse.swt.widgets.Tree.setScrollWidth(Tree.java:3917)
	at org.eclipse.swt.widgets.Tree.cellDataProc(Tree.java:353)
	at org.eclipse.swt.widgets.Display.cellDataProc(Display.java:995)
	at org.eclipse.swt.internal.gtk.GTK.gtk_tree_view_column_cell_set_cell_data(Native Method)
	at org.eclipse.swt.widgets.Tree.calculateWidth(Tree.java:443)
	at org.eclipse.swt.widgets.Tree.calculateWidth(Tree.java:518)
	at org.eclipse.swt.widgets.Tree.setScrollWidth(Tree.java:3917)
	at org.eclipse.swt.widgets.Tree.cellDataProc(Tree.java:353)
	at org.eclipse.swt.widgets.Display.cellDataProc(Display.java:995)
	at org.eclipse.swt.internal.gtk.GTK.gtk_tree_store_clear(Native Method)
	at org.eclipse.swt.widgets.Tree.removeAll(Tree.java:2989)
	at org.eclipse.jface.viewers.TreeViewer.removeAll(TreeViewer.java:289)
	at org.eclipse.jface.viewers.AbstractTreeViewer.lambda$1(AbstractTreeViewer.java:1631)
	at org.eclipse.jface.viewers.StructuredViewer.preservingSelection(StructuredViewer.java:1392)
	at org.eclipse.jface.viewers.TreeViewer.preservingSelection(TreeViewer.java:367)
	at org.eclipse.jface.viewers.StructuredViewer.preservingSelection(StructuredViewer.java:1353)
	at org.eclipse.jface.viewers.AbstractTreeViewer.inputChanged(AbstractTreeViewer.java:1627)
	at org.eclipse.debug.internal.ui.viewers.model.InternalTreeModelViewer.inputChanged(InternalTreeModelViewer.java:486)
	at org.eclipse.jface.viewers.ContentViewer.setInput(ContentViewer.java:282)
	at org.eclipse.jface.viewers.StructuredViewer.setInput(StructuredViewer.java:1636)
	at org.eclipse.debug.tests.viewer.model.StateTests.testSaveAndRestoreLarge(StateTests.java:1085)
	[...]
@mx990 mx990 added the bug Something isn't working label Aug 13, 2024
@jukzi
Copy link
Contributor

jukzi commented Aug 14, 2024

The logging was added to find the caller that uses null [1].
So instead of removing the logging the caller that passes null should be fixed. @mx990 can you provide a PR?

[1] https://bugs.eclipse.org/bugs/show_bug.cgi?id=380288#c8

mx990 added a commit to mx990/eclipse.platform that referenced this issue Aug 14, 2024
There is a logged NPE in the constructor of ViewerUpdateMonitor when
viewerInput is null. This can happen sporadically when updating tree
elements during Viewer.setInput(null).

This commit adds a check to avoid creating children updates when the
viewer input is null.

Fixes eclipse-platform#1500
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants