Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 499654

Summary: [javadoc] Javadoc of ContentAssist#computeCompletionProposals(ITextViewer, int) incorrect: it can return null
Product: [Eclipse Project] Platform Reporter: Andreas Sewe <sewe>
Component: TextAssignee: Dani Megert <daniel_megert>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: daniel_megert
Version: 4.7   
Target Milestone: 4.7 M2   
Hardware: All   
OS: All   
Whiteboard:

Description Andreas Sewe CLA 2016-08-15 04:46:52 EDT
While investigating Bug 499653 I found a possible problem in org.eclipse.jface.text.contentassist.ContentAssist#computeCompletionProposals. Contrary to what its Javadoc indicates and what its callers (at least CompletionProposalPopup#computeProposals) expect, the method can return null.

While ContentAssist#computeCompletionProposals intentionally tries to avoid exceptions (using ExceptionLoggingSafeRunnable), it can still returns null if an exception occurs within the ExceptionLoggingSafeRunnable (or if getProcessor does not return an instance of ISubjectControlContentAssistProcessor). This causes *immediate* trouble for CompletionProposalPopup#computeProposals, as that methods tries to sort the returned array -- which is null rather than empty.
Comment 1 Andreas Sewe CLA 2016-08-19 06:08:53 EDT
(In reply to Andreas Sewe from comment #0)
> While investigating Bug 499653 I found a possible problem in
> org.eclipse.jface.text.contentassist.
> ContentAssist#computeCompletionProposals. Contrary to what its Javadoc
> indicates and what its callers (at least
> CompletionProposalPopup#computeProposals) expect, the method can return null.

I just realized that I should have been more precise, as ContentAssist#computeCompletionProposals is overloaded.

- ContentAssist#computeCompletionProposals(IContentAssistSubjectControl, int):

  Javadoc says "@return an array of completion proposals", but it *can* return null.

- ContentAssist#computeCompletionProposals(ITextViewer, int):

  Javadoc correctly says "@return an array of completion proposals or <code>null</code> if no proposals are possible".

IMHO, the Javadoc in both cases should indicate that the method can return null.

> This causes *immediate* trouble for
> CompletionProposalPopup#computeProposals, as that methods tries to sort the
> returned array -- which is null rather than empty.

The above problem should probably be addressed in a separate bug -- this one is just about the incorrect Javadoc.
Comment 2 Andreas Sewe CLA 2016-08-19 07:18:15 EDT
(In reply to Andreas Sewe from comment #1)
> The above problem should probably be addressed in a separate bug -- this one
> is just about the incorrect Javadoc.

Filed Bug 499980 to track the potential NPE.