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

Bug 322651

Summary: A nullpoint exception in StructuredContentAssistProcessor.java when convert ICompletionProposal[] to List
Product: [WebTools] WTP Source Editing Reporter: zhiqing <huangtaogold>
Component: wst.xmlAssignee: Nick Sandonato <nsand.dev>
Status: RESOLVED FIXED QA Contact: Nitin Dahyabhai <thatnitind>
Severity: major    
Priority: P3 CC: nsand.dev
Version: 3.2Flags: thatnitind: review+
Target Milestone: 3.2.2   
Hardware: All   
OS: All   
Whiteboard:
Attachments:
Description Flags
patch none

Description zhiqing CLA 2010-08-13 09:23:10 EDT
Build Identifier: 20100615235519

Error Code:
while (iter.hasNext()) {
				IContentAssistProcessor legacyProcessor = (IContentAssistProcessor) iter.next();
				ICompletionProposal[] legacyComputed = legacyProcessor.computeCompletionProposals(viewer, offset);
				proposals.addAll(Arrays.asList(legacyComputed));
			}
around Line 471.
Obviously, you can see you never check whether legacyComputed is null or not.

   I call it a bug because the nullpointException gives my project a real trouble. I have a class which is named AllTagContentAssistProcessor.java in my plugin-project and it extends from the class named AbstractContentAssistProcessor.java. 
   In AllTagContentAssistProcessor.java, I override the method : protected ContentAssistRequest computeCompletionProposals(int documentPosition, String matchString,ITextRegion completionRegion, IDOMNode treeNode,IDOMNode xmlnode), and whenever there is no ICompletionProposal need to show, I makes the method return null. It works well in former versions, but now the nullpointException makes my project a real trouble.

  To solve the problem in my project, I have to use a very stupid way. I write a method to add a ICompletionProposal contains a comment proposal to the returned ContentAssistRequest like this to avoid the nullpointException:
public ContentAssistRequest fixBugs(ContentAssistRequest contentAssistRequest, int documentPosition,
			String matchString, ITextRegion completionRegion,
			IDOMNode treeNode, IDOMNode xmlnode) {
    	if( null == contentAssistRequest || null == contentAssistRequest.getCompletionProposals() || contentAssistRequest.getCompletionProposals().length == 0 ){
    		//contentAssistRequest = new ContentAssistRequest( xmlnode,  null,  getStructuredDocumentRegion(documentPosition) , completionRegion, documentPosition, 0, matchString);
    		contentAssistRequest = newContentAssistRequest(treeNode, xmlnode,getStructuredDocumentRegion(documentPosition), completionRegion, documentPosition, 0,matchString);
    		String replaceString = "<!--  -->";
    		String displayString = "comment - xml comment";
    		String additionalProposalInfo = "comment - xml comment <!--  -->";
    		ICompletionProposal proposal = new AllTagCompletionProposal(replaceString,documentPosition, 0, replaceString.indexOf(">") + 1,XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_TAG_MACRO),displayString, null, additionalProposalInfo, XMLRelevanceConstants.R_TAG_NAME, null);
    		//add a comment to avoid the WTP nullpointException bug
    		contentAssistRequest.addProposal(proposal);
    	}
    	return contentAssistRequest;
    }

Reproducible: Always
Comment 1 zhiqing CLA 2010-08-13 09:25:15 EDT
StructuredContentAssistProcessor.java Line:471
Comment 2 Nick Sandonato CLA 2010-08-13 10:14:37 EDT
Created attachment 176557 [details]
patch
Comment 3 Nick Sandonato CLA 2010-08-13 10:17:15 EDT
I think that this bug falls more in line with Major, by the severity definitions.
Comment 4 Nick Sandonato CLA 2010-08-13 10:20:21 EDT
Requesting review for the maintenance branch.
Comment 5 Nitin Dahyabhai CLA 2010-08-13 11:06:13 EDT
Approved, surprisingly null is a legal return value.
Comment 6 Nick Sandonato CLA 2010-08-18 09:57:41 EDT
Code checked in for maintenance and HEAD.