Bug 74337 FieldEditor should document that doFillIntoGrid() is called from the superclass constructor.
The doFillIntoGrid() method is called from the constructor of the FieldEditor class. This should REALLY be documented. It cost me 3 hours of work on a nasty bug. Consider the following addition to the documentation: --------------------------------------------------------------------------- <p> Developers should be aware that FieldEditor calls the doFillIntoGrid() method in its constructor. The significance of this can be demonstrated by the following snippet. </p> <pre> public class RegexPatternSetFieldEditor extends FieldEditor implements SelectionListener,IDoubleClickListener { // .... snip /** The sorted set of patterns. */ private final SortedSet patterns = new TreeSet(new RegexSortingComparator()); // .... snip public RegexPatternSetFieldEditor(final String preferenceName, final String labelText, final Composite parent) { super(preferenceName, labelText, parent); } // .... snip protected void doFillIntoGrid(final Composite parent, final int numColumns) { // .... snip this.tbvPatternList = new TableViewer(table); this.tbvPatternList.setLabelProvider(new RegexPatternLabelProvider()); this.tbvPatternList.setContentProvider( new RegexPatternsContentProvider()); this.tbvPatternList.setInput(this.patterns); // .... snip } } </pre> <p> In this case the user just set <b><code>null</code></b> as input to the table viewer, <code>tbvPatternList</code>. Once you know that this method is called from the superclass constructor, it is self-evident why. Constructors are run before initializers and therefore at the time that the constructor is calling super, <code>this.patterns</code> is <code>null<code>. However, microseconds later when the call to the <code>doFillIntoGrid()</code> is done, the initializers are run. The result is that the viewer is looking at <code>null</code> and yet this.patterns is not null. </p> ---------------------------------------------------------------------------
bundles/org.eclipse.jface/src/org/eclipse/jface/preference/FieldEditor.java
* @return the preference store, or <code>null</code> if none
     * @see #setPreferenceStore
     */
    public IPreferenceStore getPreferenceStore() {
        return preferenceStore;
    }
    /**
     * Initialize the field editor with the given preference name and label.
     * 
     * @param name the name of the preference this field editor works on
     * @param text the label text of the field editor
     */
    protected void init(String name, String text) {
        Assert.isNotNull(name);
        Assert.isNotNull(text);
        preferenceName = name;
        this.labelText = text;
    }
    /**
     * Returns whether this field editor contains a valid value.
     * <p>
     * The default implementation of this framework method
     * returns <code>true</code>. Subclasses wishing to perform
     * validation should override both this method and
     * <code>refreshValidState</code>.
     * </p>
     * 
     * @return <code>true</code> if the field value is valid,
     *   and <code>false</code> if invalid
     * @see #refreshValidState()