Skip to content

Inconsistency in TreeItem.getExpanded() between Linux and Windows #2834

@ptziegler

Description

@ptziegler

Describe the bug
In certain configurations, a call to getExpanded() returns false on Linux, but true on Windows. The result was seen in eclipse-platform/eclipse.platform.ui#3527, where "dummy" tree items are created on Linux but not on Windows, because JFace believes a tree item to be collapsed when it is not.

To Reproduce
Consider the following snippet:

public static void main(String[] args) {
	Shell shell = new Shell();
	Tree tree = new Tree(shell, SWT.FULL_SELECTION);
	TreeItem item1 = new TreeItem(tree, SWT.NONE);
	TreeItem item2 = new TreeItem(item1, SWT.NONE);
	item1.setExpanded(true);
	System.out.println(item1.getExpanded());
	item2.dispose();
	System.out.println(item1.getExpanded());
	item2 = new TreeItem(item1, SWT.NONE);
	System.out.println(item1.getExpanded());
}

On Linux, the second call to getExpanded() returns false, because the tree doesn't contain any non-disposed children. However, the item is still expanded, as otherwise the third call would also return false.
On Windows, all calls return true.

In addition, the Linux-implementation of this widget has an isExpanded field that keeps track of the expanded state. This field is true, even though getExpanded() returns false.

Expected behavior
The TreeItem widget should behave consistently across multiple platforms.

Environment:

  1. Select the platform(s) on which the behavior is seen:
    • All OS
    • Windows
    • Linux
    • macOS

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions