Bug 9262 [Viewers] Recursion with multiple equal elements in IStructuredContentProvider/ITreeContentProvider
Currently, IStructuredContentProvider does not restrict the output of getElements(Object input). However, the following code produces a bug: public class MyContentProvider implements TreeContentProvider { ... public Object[] getElements(Object input) { return new Object[] {input}; } } If MyContentProvider is supplied to a TreeViewer, the result is an infinite tree. (The node representing 'input' has one child, which is a node representing 'input', and this situation recurses forever.) It seems that a comparison is being made somewhere so that if a node is equal to the input, getElements is called, otherwise, getChildren is called. So, the array returned by getElements cannot contain the input object. Either the spec on IStructuredContentProvider should be changed to restrict the returned array, or the logic in TreeViewer (and any other viewer with this problem) that determines whether an object is the root or a child should be made more general.
bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/IStructuredContentProvider.java
/*******************************************************************************
 * Copyright (c) 2000, 2006 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.jface.viewers;
/**
 * An interface to content providers for structured viewers.
 *
 * @see StructuredViewer
 */
public interface IStructuredContentProvider extends IContentProvider {
    /**
     * Returns the elements to display in the viewer 
     * when its input is set to the given element. 
     * These elements can be presented as rows in a table, items in a list, etc.
     * The result is not modified by the viewer.
     *
     * @param inputElement the input element
     * @return the array of elements to display in the viewer
     */
    public Object[] getElements(Object inputElement);
}