Skip to main content

NullPointerException in AutoCompleteDocument in 0.9.4

No replies
s_mc
Offline
Joined: 2007-11-02

folks,

just upgraded to 0.9.4, and ran into a NPE when creating a new AutoCompleteDocument.

Affected constructor:

<br />
    public AutoCompleteDocument(AbstractAutoCompleteAdaptor adaptor, boolean strictMatching,<br />
            ObjectToStringConverter stringConverter, Document delegate) {<br />
        this.adaptor = Contract.asNotNull(adaptor, "adaptor cannot be null");<br />
        this.strictMatching = strictMatching;<br />
        this.stringConverter = stringConverter == null ? DEFAULT_IMPLEMENTATION : stringConverter;<br />
        this.delegate = delegate == null ? new PlainDocument() : delegate;</p>
<p>        // Handle initially selected object<br />
        Object selected = adaptor.getSelectedItem();<br />
        if (selected!=null) setText(stringConverter.getPreferredStringForItem(selected));<br />
        adaptor.markEntireText();<br />
    }<br />

where the line with
if (selected!=null) setText(stringConverter.getPreferredStringForItem(selected)); should be changed to if (selected!=null) setText(this.stringConverter.getPreferredStringForItem(selected));

Issue filed @ https://swingx.dev.java.net/issues/show_bug.cgi?id=938

Work-around:
Supply the default implementation of the ObjectToStringConverter to the AutoCompleteDocument constructor.

cheers - s_mc