Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 388628

Summary: [Viewers] ILazyTreeContentProvider: NPE when refreshing viewer while an inner node is selected and using OwnerDrawLabelProvider
Product: [Eclipse Project] Platform Reporter: Missing name <harely>
Component: UIAssignee: Carolyn MacLeod <carolynmacleod4>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: carolynmacleod4, daniel_megert, eclipse, pelder.eclipse, pwebster, Silenio_Quarti
Version: 3.7Keywords: helpwanted
Target Milestone: 4.3 M6Flags: Silenio_Quarti: review+
Hardware: PC   
OS: Windows XP   
Whiteboard:
Attachments:
Description Flags
Code reproducing the problem none

Description Missing name CLA 2012-09-02 12:38:26 EDT
Created attachment 220635 [details]
Code reproducing the problem

When using an ILazyTreeContentProvider with an OwnerDrawLabelProvider: if the model changes while an inner node is selected, so that it is no longer there, NullPointerException is thrown during viewer refresh from line:
org.eclipse.jface.viewers.AbstractTreeViewer.getSelection(AbstractTreeViewer.java:2956)



To reproduce the problem with the attached code:
 - expand /root/1
 - select /root/1/0
 - click the button on the right to change the model and refresh
Comment 1 Thomas Singer CLA 2012-12-13 06:10:45 EST
A couple of users of our SmartGit also report this error. Is there a way to work around this bug in our code?
Comment 2 Paul Webster CLA 2012-12-13 10:39:22 EST
Thomas, I don't think so.

PW
Comment 3 Thomas Singer CLA 2013-01-29 03:13:04 EST
Please try to fix this bug ASAP. There is no day where we don't get at least one user of SmartGit who reports this bug.
Comment 4 Paul Webster CLA 2013-01-29 09:26:59 EST
No one is looking at this.  We will review a patch if submitted.  See http://wiki.eclipse.org/Platform_UI/How_to_Contribute

PW
Comment 5 Thomas Singer CLA 2013-01-29 12:38:11 EST
Just curious, does the Eclipse project not use the ILazyTreeContentProvider?
Comment 6 Dani Megert CLA 2013-01-30 06:21:16 EST
(In reply to comment #5)
> Just curious, does the Eclipse project not use the ILazyTreeContentProvider?

Nope, and that's why I always insist not to add API for things that we do not use ourselves. We use org.eclipse.jface.viewers.ILazyTreePathContentProvider though.
Comment 7 Carolyn MacLeod CLA 2013-01-31 16:26:00 EST
Changing one boolean from false to true in SWT Tree.releaseItem () fixes the problem, however I need to know why the boolean was false to begin with,
before I can release this code.

SSQ, can we look at this together on Monday?

It was failing because the selected leaf node was only partly destroyed when a call to tree.getSelection() was done (during dispose, which wants to paint, which wants to measure and getdata, which the TreeViewer uses as an excuse to update <g>, which calls getSelection()). So during that getSelection(), the platform still said "this node is selected", but the item was already removed from the tree's items list, so null was being returned. Calling item.release (true) fully destroys the leaf node in the platform so that the tree's list of items is consistent with the platform's representation of the tree. But what I don't get is why we were calling item.release (false) before? Was it just a bug, or was there some good reason why we weren't destroying the leaf item in the platform right away?

void releaseItem (long /*int*/ hItem, TVITEM tvItem, boolean release) {
   if (hItem == hAnchor) hAnchor = 0;
   if (hItem == hInsert) hInsert = 0;
   tvItem.hItem = hItem;
   if (OS.SendMessage (handle, OS.TVM_GETITEM, 0, tvItem) != 0) {
      if (tvItem.lParam != -1) {
         if (tvItem.lParam < lastID) lastID = (int)/*64*/tvItem.lParam;
         if (release) {
            TreeItem item = items [(int)/*64*/tvItem.lParam];
>>>         if (item != null) item.release (true);  // why was this false??
         }
         items [(int)/*64*/tvItem.lParam] = null;
      }
   }
}
Comment 8 Thomas Singer CLA 2013-02-01 02:15:45 EST
Carolyn, these are really good news! As a temporary work-around we used a non-lazy tree.
Comment 9 Carolyn MacLeod CLA 2013-02-05 16:20:40 EST
Released a patch to 4.3 master that fixes this problem.
It's not pretty, but it's simple.
SSQ, please review, before I mark this bug fixed.

http://git.eclipse.org/c/platform/eclipse.platform.swt.git/commit/?id=1a14ea69ecd8828d401196778d87114e683d18b8
Comment 10 Carolyn MacLeod CLA 2013-02-07 10:28:28 EST
Marking the bug fixed. The fix is in master, and it will be in 4.3 (Kepler) M6.
Comment 11 Paul Elder CLA 2013-03-12 10:39:04 EDT
Verified in 4.3.0.I20130311-2000