eclipse-platform / eclipse.platform

https://eclipse.dev/eclipse/
Eclipse Public License 2.0
81 stars 112 forks source link

Logged NPE in ViewerUpdateMonitor constructor #1500

Open mx990 opened 2 months ago

mx990 commented 2 months ago

There is a logged NPE due to viewerInput being null in the constructor of ViewerUpdateMonitor when updating tree elements during Viewer.setInput(null): https://github.com/eclipse-platform/eclipse.platform/blob/b469dee78f959320d018d3607d74fc24da69f7cd/debug/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/model/ViewerUpdateMonitor.java#L86-L91

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)
    [...]
jukzi commented 2 months ago

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