JFace Bug 9262

Just a quick tip about JFace viewers.

JFace Bug 9262

JFace Bug 9262

Wondering where this bug comes from ??? After 10mn about reading again and again my code to figure out why my SWT tree was showing recursively (infinitely) my root object, I finally suspected JFace (without convictions) and reached this bug, source of my problem.

According to the Javadoc of the IStructuredContentProvider. public Object[] getElements(Object inputElement) method you can’t return a single item object array containing only inputElement.

“NOTE: For instances where the viewer is displaying a tree containing a single ‘root’ element it is still necessary that the ‘input’ does not return itself from this method. This leads to recursion issues (see bug 9262).”

To solve this issue I just created a new class for my root object and instead of returning an object containing the inputElement I return an array containing a new instance of this root element (having of course a reference on the inputElement).


This entry was posted in Uncategorized by Manuel. Bookmark the permalink.

5 thoughts on “JFace Bug 9262

  1. I think this happens to everybody the first time they try to write a content provider for a tree viewer. Thanks for pointing out that there is a bug open about it.

  2. Thanks Manuel,

    fortunately I realised pretty quickly about the bug (thanks to Javadoc).

    I had no idea how to fix it until I read your post.

  3. Hi Manuel,

    I was trying to write my own content provider for a JFace tree when I got stuck at the very same problem as you. The screenshot made it very clear :)

    I still did not understand what the solution is. I’m trying to create a tree from an XML file. For that, I have two classes – ‘Element’ and ‘Attribute’. Each element in the raw XML file is an ‘Element’-Object. What should I do with the root? Should I create a separate class, named ‘RootElement’, which has exactly the same properties as the ‘Element’ class?

    Thanks in advance,


  4. Hi Darie,

    The problem here, is about the input of your viewer and the returned array in the Content Provider getElements method.

    What are you passing as input to your viewer through the setInputMethod(Object input) ??

    I guess you are passing an Element object isnt’it ? You should pass a RootElement element instead, as you mentioned but not with the same properties.

    Just create the RootElement class with one Element as attribute called root and one getRoot() method returning this element and set the viewer’s input with this object.

    Then implements the content provider getElement(Object inputElement) method as following:

    return {((RootElement)inputElement).getRoot()};

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s