Bug 44647 - NPE code completion
Summary: NPE code completion
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.0   Edit
Hardware: PC Windows 2000
: P3 normal (vote)
Target Milestone: 3.0 M5   Edit
Assignee: David Audel CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-10-10 09:52 EDT by Nikolay Metchev CLA
Modified: 2003-11-19 10:47 EST (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Nikolay Metchev CLA 2003-10-10 09:52:41 EDT
----------------------------------A.java---------------------------
public class A
{
   public A(final String str1, final String str2)
   {
      
   }
   
   private A[] methodA(final String str1, final String str2)
      {
         return new A[]
         {
            new A(str1, str2)
            {
               //initialiser!
               {
                  methodA("1", "2");
               }
            },
            new A("hello".c) //<--------code complete to "hello".concat()
         };
      
      }
}
---------------------------------------------------------------
if you code complete above to "hello".concat() you get:

java.lang.NullPointerException
	at 
org.eclipse.jdt.internal.codeassist.CompletionEngine.computeExpectedTypes
(CompletionEngine.java:3171)
	at org.eclipse.jdt.internal.codeassist.CompletionEngine.complete
(CompletionEngine.java:415)
	at org.eclipse.jdt.internal.codeassist.CompletionEngine.complete
(CompletionEngine.java:957)
	at org.eclipse.jdt.internal.core.Openable.codeComplete
(Openable.java:133)
	at org.eclipse.jdt.internal.core.CompilationUnit.codeComplete
(CompilationUnit.java:189)
	at org.eclipse.jdt.internal.core.CompilationUnit.codeComplete
(CompilationUnit.java:183)
	at 
org.eclipse.jdt.internal.ui.text.java.ParameterGuesser$VariableCollector.collect
(ParameterGuesser.java:132)
	at 
org.eclipse.jdt.internal.ui.text.java.ParameterGuesser.parameterProposals
(ParameterGuesser.java:349)
	at 
org.eclipse.jdt.internal.ui.text.java.ParameterGuessingProposal.guessParameters
(ParameterGuessingProposal.java:205)
	at 
org.eclipse.jdt.internal.ui.text.java.ParameterGuessingProposal.computeGuessingC
ompletion(ParameterGuessingProposal.java:230)
	at org.eclipse.jdt.internal.ui.text.java.ParameterGuessingProposal.apply
(ParameterGuessingProposal.java:121)
	at org.eclipse.jdt.internal.ui.text.java.JavaCompletionProposal.apply
(JavaCompletionProposal.java:495)
	at 
org.eclipse.jface.text.contentassist.CompletionProposalPopup.insertProposal
(CompletionProposalPopup.java:333)
	at 
org.eclipse.jface.text.contentassist.CompletionProposalPopup.selectProposalWithM
ask(CompletionProposalPopup.java:302)
	at 
org.eclipse.jface.text.contentassist.CompletionProposalPopup.verifyKey
(CompletionProposalPopup.java:599)
	at 
org.eclipse.jface.text.contentassist.ContentAssistant$InternalListener.verifyKey
(ContentAssistant.java:601)
	at org.eclipse.jface.text.TextViewer$VerifyKeyListenersManager.verifyKey
(TextViewer.java:369)
	at org.eclipse.swt.custom.StyledTextListener.handleEvent
(StyledTextListener.java:55)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:82)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:847)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:871)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:856)
	at org.eclipse.swt.widgets.Widget.notifyListeners(Widget.java:664)
	at org.eclipse.swt.custom.StyledText.handleKeyDown(StyledText.java:5310)
	at org.eclipse.swt.custom.StyledText$8.handleEvent(StyledText.java:5058)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:82)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:847)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:871)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:856)
	at org.eclipse.swt.widgets.Control.sendKeyEvent(Control.java:1689)
	at org.eclipse.swt.widgets.Control.sendKeyEvent(Control.java:1685)
	at org.eclipse.swt.widgets.Control.WM_CHAR(Control.java:3001)
	at org.eclipse.swt.widgets.Control.windowProc(Control.java:2889)
	at org.eclipse.swt.widgets.Display.windowProc(Display.java:2698)
	at org.eclipse.swt.internal.win32.OS.DispatchMessageW(Native Method)
	at org.eclipse.swt.internal.win32.OS.DispatchMessage(OS.java:1343)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:1861)
	at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2106)
	at org.eclipse.ui.internal.Workbench.run(Workbench.java:2089)
	at org.eclipse.core.internal.boot.InternalBootLoader.run
(InternalBootLoader.java:858)
	at org.eclipse.core.boot.BootLoader.run(BootLoader.java:461)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke
(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke
(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:324)
	at org.eclipse.core.launcher.Main.basicRun(Main.java:298)
	at org.eclipse.core.launcher.Main.run(Main.java:764)
	at org.eclipse.core.launcher.Main.main(Main.java:598)
Comment 1 David Audel CLA 2003-10-10 10:39:44 EDT
I can not reproduce the problem in build I20031009.

Which build are you using ?
Comment 2 Nikolay Metchev CLA 2003-10-10 10:41:37 EDT
I200309300800
Comment 3 David Audel CLA 2003-10-10 11:44:03 EDT
I can not reproduce in build I200309300800

Do you obtain the NPE with this exact test case ?

The stack trace suggest that the code look like the following code.
public class A {
   ...
   private A[] methodA() {
      ...
      X x = "hello".c
      ...
   }
...
}
And the NPE should occur because the type of the variable declaration should be 
null.
Comment 4 Nikolay Metchev CLA 2003-10-10 11:50:26 EDT
I just copied and pasted the exact test case and I got the NPE! That is 
definately the exact test case! If the latest integration build has no junit 
failures I will download it and try it on that!
Comment 5 Nikolay Metchev CLA 2003-10-13 09:12:08 EDT
I can confirm that the same things happens in M4!
Comment 6 David Audel CLA 2003-10-14 07:06:09 EDT
I can reproduce the problem in 3.0M4. To reproduce it, "Fill argument names on 
method completion" must be enabled.
Comment 7 David Audel CLA 2003-10-16 05:44:15 EDT
Fixed and regression test added.
Comment 8 David Audel CLA 2003-11-19 10:47:04 EST
Verified.