Bug 230885 - [content assist] NPE at ParameterGuesser.createVariable()
Summary: [content assist] NPE at ParameterGuesser.createVariable()
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.4   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.4 RC1   Edit
Assignee: David Audel CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-05-07 09:33 EDT by Philippe Coucaud CLA
Modified: 2008-05-14 05:20 EDT (History)
2 users (show)

See Also:
jerome_lanneluc: review+


Attachments
call stack (6.06 KB, text/plain)
2008-05-07 09:33 EDT, Philippe Coucaud CLA
no flags Details
Proposed fix (14.25 KB, patch)
2008-05-12 10:59 EDT, David Audel CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Philippe Coucaud CLA 2008-05-07 09:33:16 EDT
Created attachment 99066 [details]
call stack

cf attached stack trace
Comment 1 Dani Megert CLA 2008-05-07 09:37:48 EDT
Any steps to reproduce?
Comment 2 Dani Megert CLA 2008-05-07 09:45:14 EDT
Looked through the call hierarchy and it seems that org.eclipse.jdt.core.CompletionContext.getVisibleElements(String) returns 'null'.
Comment 3 Jerome Lanneluc CLA 2008-05-07 09:52:42 EDT
Looking at the code, I don't see a path were it could possibly return null. David can you please confirm?
Comment 4 Philippe Coucaud CLA 2008-05-07 10:22:31 EDT
I can reproduce the NPE with a debug instance of Eclipse. In ParameterGuesser.parameterProposals(), 'suggestions' is an array of 3 elements. The first element is null. If you tell me where to put breakpoints I can try to provide more information.
Comment 5 David Audel CLA 2008-05-07 10:24:01 EDT
It is not possible to getVisibleElements() return null. An array is always returned but looking at the code i found a path where the array can contain a null value.

Currently i have no real test case to reproduce the bug.
Comment 6 Philippe Coucaud CLA 2008-05-07 10:26:22 EDT
I can reproduce the NPE with a debug instance of Eclipse. In
ParameterGuesser.parameterProposals(), 'suggestions' is an array of 3 elements.
The first element is null. If you tell me where to put breakpoints I can try to
provide more information.
Comment 7 David Audel CLA 2008-05-07 10:28:19 EDT
Can you put a breakpoint in InternalExtendedCompletionContext#getJavaElement() and look if this method is called and return null ?
Comment 8 Philippe Coucaud CLA 2008-05-07 10:36:30 EDT
Yes, it is called and returns null because of the following statement (line 250):

    if (parent == null) return null;
Comment 9 Philippe Coucaud CLA 2008-05-07 10:43:18 EDT
The first branch is taken ('referenceContext instanceof AbstractMethodDeclaration'), meaning that 'parent' remains null after the call to getJavaElementOfCompilationUnit(). 'methodDeclaration.binding' is null.
Comment 10 Jerome Lanneluc CLA 2008-05-07 10:48:53 EDT
Philippe, a test case demonstrating the problem would help even more.

David, I think we should still protect ourselves and shrink the array if it contains nulls.
Comment 11 Philippe Coucaud CLA 2008-05-07 11:02:12 EDT
I can reproduce the NPE with the following class: 

public class Foo  {

	private void addDepencency(int source, int target, int depth) {
	}

	private void addDataDependencies(int source) {
		addD
	}

	private void addDataDependencies(int source) {
	}
}

Just trigger the completion after "addD".
Comment 12 Jerome Lanneluc CLA 2008-05-07 11:27:02 EDT
Thanks Philippe. I was able to reproduce. David please investigate for RC1.
Comment 13 David Audel CLA 2008-05-12 10:59:59 EDT
Created attachment 99725 [details]
Proposed fix

With this patch:
- getVisibleElements() can not return an array with a null value.
- getVisibleElements() return elements which have a parent with no corresponding binding (like duplicate methods)
- AssistSourceField#getKey() and AssistSourceMethod#getKey() andAssistSourceType#getKey() always return a key and never return null.
Comment 14 David Audel CLA 2008-05-12 11:16:09 EDT
Jerome - Could you review my patch ?
Comment 15 Jerome Lanneluc CLA 2008-05-12 11:23:59 EDT
Patch looks good. +1
Comment 16 David Audel CLA 2008-05-12 11:26:43 EDT
Released for 3.4RC1.

Tests added
  CompletionContextTests#test0163() -> test0164()
Comment 17 Jerome Lanneluc CLA 2008-05-14 05:20:07 EDT
Verified for 3.4RC1 using I20080513-2000