Bug 16883 - Variable sorting changes unexpectedly
Summary: Variable sorting changes unexpectedly
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 2.0   Edit
Hardware: PC Linux-GTK
: P1 critical (vote)
Target Milestone: 2.0 F2   Edit
Assignee: Boris Shingarov CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 17570 (view as bug list)
Depends on:
Blocks:
 
Reported: 2002-05-22 12:05 EDT by Jared Burns CLA
Modified: 2002-06-19 16:35 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jared Burns CLA 2002-05-22 12:05:48 EDT
1. Debug the following program to a breakpoint on the first line of foo(). 
Variables view looks like:
  this = VariableTest
2. Perform a step over.
Variables view looks like:
  x = 1
  this = VariableTest
3. Perform a step over.
Variables view looks like:
  this = VariableTest
  y = 2
  x = 1

The ordering of existing variables shouldn't change when new variables are 
added.

public class VariableTest {
  public static void main(String[] args) {
    new VariableTest().foo();
  }
  private void foo() {
    int x= 1;  // BREAKPOINT HERE
    int y= 2;
    System.out.println("Grah");
  }
}
Comment 1 Jared Burns CLA 2002-05-22 12:12:35 EDT
A side-effect of the reordering is that expanded variables are collapsed.
Comment 2 Jared Burns CLA 2002-05-29 15:46:12 EDT
This appears to be a UI/SWT problem. Reassigning to UI.

Information which may be useful for debugging this problem:
1. Launch a TARGET Eclipse.
2. In the TARGET, create the test case above and launch it in debug mode 
such that it suspends at the breakpoint.
3. In the HOST, put a breakpoint in 
AbstractTreeViewer#internalRefresh(Widget, Object, boolean) on line 842, 
which reads:
  Item[] children= getChildren(widget);
4. In the TARGET, click "Step Over."
5. The HOST will suspend at the breakpoint a couple times with many stack 
frames from LaunchViewer. Resume until it suspends with calls from 
VariablesViewer on the stack (for me, I have to resume twice).
6. Expand "widget" in the variables view and take a look at its tree items. 
item[0] has a JDIThisVariable. item[1] has a JDILocalVariable. This is the 
correct ordering for display.
7. Step over the call to getChildren(widget); and examine the collection of 
items in the children array. children[0] has a JDILocalVariable. 
children[1] has a JDIThisVariable. It seems that the call to getChildren(), 
which ultimately ends up in Tree.getChildren() is returning the children in 
reverse order in this case.
Comment 3 Nick Edgar CLA 2002-05-29 15:57:41 EDT
getChildren(widget) gets the items out of the widget, so this must be after the 
problem occurs.  Need to look at call to getSortedChildren(element).
Comment 4 Nick Edgar CLA 2002-05-29 16:00:44 EDT
Jared, if you have time can you look at the call to getSortedChildren.
I'd be very surprised if there is a bug in the viewers here since we just sort 
the collection using the java.util classes and then process the items in order.
I suspect a problem with your sorter.

Also, what notifications do you get from JDI for the appearance of a new 
variable?  If you get told about individual variables coming into scope, it 
would be better to use add rather than refresh.
Comment 5 Jared Burns CLA 2002-05-29 16:07:11 EDT
I debugged the problem to the current test case by stepping through the 
getSortedItems() call that results from the updateChildren() call just 
above the breakpoint. At the location I indicated, we've already got the 
items from the content provider, run them through any filters, and the 
sorter (there actually isn't one).

As explained in the test case, the items are in the correct order in the 
Tree. I actually debugged this down into the Tree implementation and it 
appears to be a GTK bug - I don't know enough to say if it's our GTK 
natives or GTK itself.

From org.eclipse.swt.widgets.Tree (my comments inserted):
TreeItem [] getItems (int node) {
...
// At this point in the method, this.items[] has the items in the correct 
order.
	Items = new TreeItem [Count];
	Count = 0;
	Callback GtkCTreeGetItems = new Callback (this, "GtkCTreeGetItems", 
3);
	int address1 = GtkCTreeGetItems.getAddress ();
	OS.gtk_ctree_post_recursive_to_depth (handle, node, depth, 
address1, node);
	GtkCTreeGetItems.dispose ();
// At this point, Items contains the TreeItems from this.items[] but in 
reverse order.
	TreeItem [] result = Items;
	Items = null;
	return result;
}

We've tested on Win2K and Linux-Motif and verified that this problem 
DOESN'T exist on those platforms. Recommend moving to SWT.
Comment 6 Mike Wilson CLA 2002-05-30 10:10:05 EDT
Is the bug that you are seeing that the tree does not return the items in the 
order they show up in the widget? If so, then this is a serious problem, but 
may not be something we can fix. Boris, please investigate.
Comment 7 Jared Burns CLA 2002-05-30 10:26:17 EDT
That's correct. The widget shows the items listed in the order that our 
content provider game them:
ThisVariable
LocalVariable
but the Tree is returning them in the reverse order in this case.
Comment 8 Boris Shingarov CLA 2002-06-03 01:23:18 EDT
Fixed.
This was not related to the order of returned items, but rather insertion of new
items was bogus (see Tree.GtkCTreeFindSibling()).
Comment 9 Boris Shingarov CLA 2002-06-19 16:35:31 EDT
*** Bug 17570 has been marked as a duplicate of this bug. ***