Bug 12651 - NPE out of the CompletionEngine
Summary: NPE out of the CompletionEngine
Status: RESOLVED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 2.0   Edit
Hardware: PC All
: P1 normal (vote)
Target Milestone: 2.0 M5   Edit
Assignee: David Audel CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 9128
  Show dependency tree
 
Reported: 2002-04-02 16:08 EST by Darin Swanson CLA
Modified: 2002-04-09 05:20 EDT (History)
0 users

See Also:


Attachments
Sample.java (853 bytes, text/plain)
2002-04-03 16:02 EST, Darin Swanson CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Darin Swanson CLA 2002-04-02 16:08:34 EST
I believe there is a bug in the 
org.eclipse.jdt.internal.codeassist.CompletionEngine.  When I am code assisting 
in the detail pane of the variables view for a class such as "Sample$1
$InnerClass"  I get the following NPE.  

I believe the completion engine should be using the topLevelType instead of the 
type at line 598 to generate the typeDeclaration.

NPE:
java.lang.NullPointerException
	at org.eclipse.jdt.internal.codeassist.CompletionEngine.complete
(CompletionEngine.java:605)
	at org.eclipse.jdt.internal.core.SourceType.codeComplete
(SourceType.java:68)
	at 
org.eclipse.jdt.internal.debug.ui.display.DetailsCompletionProcessor.computeComp
letionProposals(DetailsCompletionProcessor.java:64)
	at 
org.eclipse.jface.text.contentassist.ContentAssistant.computeCompletionProposals
(ContentAssistant.java:1197)
	at 
org.eclipse.jface.text.contentassist.CompletionProposalPopup.computeProposals
(CompletionProposalPopup.java:103)
	at org.eclipse.jface.text.contentassist.CompletionProposalPopup.access$3
(CompletionProposalPopup.java:102)
	at org.eclipse.jface.text.contentassist.CompletionProposalPopup$1.run
(CompletionProposalPopup.java:71)
	at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:56)
	at 
org.eclipse.jface.text.contentassist.CompletionProposalPopup.showProposals
(CompletionProposalPopup.java:66)
	at org.eclipse.jface.text.contentassist.ContentAssistant$2.run
(ContentAssistant.java:265)
	at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:29)
	at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages
(Synchronizer.java:93)
	at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.java:1397)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:1211)
	at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:755)
	at org.eclipse.ui.internal.Workbench.run(Workbench.java:738)
	at org.eclipse.core.internal.boot.InternalBootLoader.run
(InternalBootLoader.java:777)
	at org.eclipse.core.boot.BootLoader.run(BootLoader.java:319)
	at EclipseRuntimeLauncher.main(EclipseRuntimeLauncher.java:14)
Comment 1 David Audel CLA 2002-04-03 05:54:33 EST
I can not reproduce this problem.
Could you give me a more accurate test case ?
Comment 2 Darin Swanson CLA 2002-04-03 16:02:04 EST
Created attachment 543 [details]
Sample.java
Comment 3 Darin Swanson CLA 2002-04-03 16:06:00 EST
Test Case (using latest code in HEAD on dev.eclipse.org):
Use the attached source (Sample.java), breakpoint on line 32.
Debug, hit breakpoint
Go to the variables view showing the detail pane
Select the "this" variable
Code assist in the detail pane (popup menu or ctrl-space)


Comment 4 David Audel CLA 2002-04-04 04:32:46 EST
There is an error in my code. I correct it and now NPE does not occur.

But with this test case no completion proposal are possible because the 
completion is on the member type Sample.InnerClass and this type does not exist.

Fixed.
Comment 5 Darin Swanson CLA 2002-04-08 15:40:37 EDT
Doing a code completion in the Java Editor at line 36 with
"this." gives the following completions:
innerClassVar1
innerClassIVar1
innerMethod1(String innerArg1)
<<all the methods inherited from Object>>

Doing it with the "this" variable selected in the variables view with "this." 
entered in the detail pane we get no completions

why is this different?
Comment 6 David Audel CLA 2002-04-09 05:20:10 EDT
In DisplayCompletionProcessor#getType you use IType#getType. This method can 
give a handle on member type, but not local type and not anonymous type. In 
fact it is not possible to create a handle on local or anonymous.


DisplayCompletionProcessor
------------------------------------------------------
protected IType getType( ... ) throws DebugException {

   ...

   try {

      ...

      for (int i = 1; i < typeNames.length; i++) {
         String innerTypeName= typeNames[i];
         try {
            Integer.parseInt(innerTypeName);
            continue; //loop over anonymous types
         } catch (NumberFormatException e) {
         }
         type = type.getType(innerTypeName);
      }
   } catch (JavaModelException e) {
      throw new DebugException(e.getStatus());
   }
		
   return type;	
}
------------------------------------------------------
The enclosing type of the completion is the local type Sample$1$InnerClass. But 
in this algorithm the result is a handle on member type Sample$InnerClass and 
this member type does not exist. That's why there is no completion.