Community
Participate
Working Groups
Build Identifier: 3.6M6 null Error Thu Apr 29 12:46:40 CEST 2010 Unhandled event loop exception java.lang.NullPointerException at org.eclipse.jdt.internal.codeassist.InternalExtendedCompletionContext.getVisibleElements(InternalExtendedCompletionContext.java:351) at org.eclipse.jdt.internal.codeassist.InternalCompletionContext.getVisibleElements(InternalCompletionContext.java:318) at org.eclipse.jdt.internal.ui.text.java.ParameterGuessingProposal.getAssignableElements(ParameterGuessingProposal.java:110) at org.eclipse.jdt.internal.ui.text.java.ParameterGuessingProposal.guessParameters(ParameterGuessingProposal.java:290) at org.eclipse.jdt.internal.ui.text.java.ParameterGuessingProposal.computeGuessingCompletion(ParameterGuessingProposal.java:225) at org.eclipse.jdt.internal.ui.text.java.ParameterGuessingProposal.computeReplacementString(ParameterGuessingProposal.java:191) at org.eclipse.jdt.internal.ui.text.java.LazyJavaCompletionProposal.getReplacementString(LazyJavaCompletionProposal.java:308) at org.eclipse.jdt.internal.ui.text.java.AbstractJavaCompletionProposal.apply(AbstractJavaCompletionProposal.java:369) at org.eclipse.jdt.internal.ui.text.java.JavaMethodCompletionProposal.apply(JavaMethodCompletionProposal.java:55) at org.eclipse.jdt.internal.ui.text.java.ParameterGuessingProposal.apply(ParameterGuessingProposal.java:120) at org.eclipse.jdt.internal.ui.text.java.AbstractJavaCompletionProposal.apply(AbstractJavaCompletionProposal.java:482) at org.eclipse.jface.text.contentassist.CompletionProposalPopup.insertProposal(CompletionProposalPopup.java:928) at org.eclipse.jface.text.contentassist.CompletionProposalPopup.insertSelectedProposalWithMask(CompletionProposalPopup.java:879) at org.eclipse.jface.text.contentassist.CompletionProposalPopup.verifyKey(CompletionProposalPopup.java:1305) at org.eclipse.jface.text.contentassist.ContentAssistant$InternalListener.verifyKey(ContentAssistant.java:806) at org.eclipse.jface.text.TextViewer$VerifyKeyListenersManager.verifyKey(TextViewer.java:489) at org.eclipse.swt.custom.StyledTextListener.handleEvent(StyledTextListener.java:65) at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84) at org.eclipse.swt.widgets.Display.sendEvent(Display.java:3725) at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1333) at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1356) at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1341) at org.eclipse.swt.widgets.Widget.notifyListeners(Widget.java:1155) at org.eclipse.swt.custom.StyledText.handleKeyDown(StyledText.java:5944) at org.eclipse.swt.custom.StyledText$7.handleEvent(StyledText.java:5643) at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84) at org.eclipse.swt.widgets.Display.sendEvent(Display.java:3725) at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1333) at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1356) at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1341) at org.eclipse.swt.widgets.Widget.sendKeyEvent(Widget.java:1370) at org.eclipse.swt.widgets.Widget.sendKeyEvent(Widget.java:1366) at org.eclipse.swt.widgets.Canvas.sendKeyEvent(Canvas.java:416) at org.eclipse.swt.widgets.Control.doCommandBySelector(Control.java:957) at org.eclipse.swt.widgets.Display.windowProc(Display.java:5005) at org.eclipse.swt.internal.cocoa.OS.objc_msgSend(Native Method) at org.eclipse.swt.internal.cocoa.NSResponder.interpretKeyEvents(NSResponder.java:56) at org.eclipse.swt.widgets.Composite.keyDown(Composite.java:543) at org.eclipse.swt.widgets.Display.windowProc(Display.java:4915) at org.eclipse.swt.internal.cocoa.OS.objc_msgSendSuper(Native Method) at org.eclipse.swt.widgets.Widget.callSuper(Widget.java:221) at org.eclipse.swt.widgets.Widget.windowSendEvent(Widget.java:1909) at org.eclipse.swt.widgets.Shell.windowSendEvent(Shell.java:1994) at org.eclipse.swt.widgets.Display.windowProc(Display.java:4977) at org.eclipse.swt.internal.cocoa.OS.objc_msgSendSuper(Native Method) at org.eclipse.swt.widgets.Display.applicationSendEvent(Display.java:4527) at org.eclipse.swt.widgets.Display.applicationProc(Display.java:4604) at org.eclipse.swt.internal.cocoa.OS.objc_msgSend(Native Method) at org.eclipse.swt.internal.cocoa.NSApplication.sendEvent(NSApplication.java:115) at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3238) at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2416) at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2380) at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2229) at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:504) at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332) at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:497) at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149) at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:115) at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196) at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110) at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79) at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:369) at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179) 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:597) at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:619) at org.eclipse.equinox.launcher.Main.basicRun(Main.java:574) at org.eclipse.equinox.launcher.Main.run(Main.java:1406) Reproducible: Sometimes
Any steps to reproduce.
The NPE occurs on the line: if (assignableTypeBinding != null && !binding.type.isCompatibleWith(assignableTypeBinding)) continue next;
Sorry, no steps. I just found them 2-3 times in my error log.
Since this cant be reproduced as of now, I'm tempted to close this as WORKSFORME. Please report with steps if this can be reproduced. Thanks!
No steps yet. Closing as WORKSFORME. Please reopen if you have steps.
(In reply to comment #5) > No steps yet. Closing as WORKSFORME. Please reopen if you have steps. That's disappointing. According to comment 2 there are not may ways to fail with a NPE.
(In reply to comment #6) > (In reply to comment #5) > > No steps yet. Closing as WORKSFORME. Please reopen if you have steps. > > That's disappointing. According to comment 2 there are not may ways to fail > with a NPE. Thats correct. Yet, without any reproducible scenario, I dont think just adding a guard against null on that statement would be sufficient. The problem might be occuring because of some incorrect parameter passed somewhere, and might be in a completely different place altogether. Adding a guard here(which may not even be required at all) would no doubt prevent an NPE, but we'll end up with no proposals. Its better to reproduce the issue and fix the root cause IMO.
Adding a null guard without knowing what's going on would indeed be wrong. But another approach to resolve the issue is to read the surrounding code and then make an informed guess about the circumstances that could cause an NPE there. My guess was that the type of the variable cannot be resolved due to a compile error, so I tried to create some broken code where that could be the case. To reproduce, invoke content assist after "foo" on the last line of bar() here: package p; class Bug { void foo(Object o) { } <T> void bar() { T<T> loc= 12; foo } }
Thanks Markus. I'll investigate.
(In reply to comment #9) > Thanks Markus. I'll investigate. The problem comes in only some peculiar cases where we return null as the resolved type for the binding because of erroneous code, such as when hierarchy cycle is detected, incorrect arity for parameterized type, when non-generic type is parameterized (shown by above example), etc. (See org.eclipse.jdt.internal.compiler.ast.ParameterizedSingleTypeReference.internalResolveType(Scope, ReferenceBinding, boolean) ). In other case such as these: void bar() { Zar loc= 12; // unknown type Zar foo } we return a missing type binding, which saves the NPE. So in this case, the best approach is to add a null check for binding.type on the line if (assignableTypeBinding != null && !binding.type.isCompatibleWith(assignableTypeBinding)) continue next; Working on a patch with tests.
Another test package p; class Bug<A1,A2> { void foo(Object o) { } void bar() { Bug<String,String,String> bug; foo| } }
Created attachment 180424 [details] proposed fix v1.0 + regression tests Olivier, please review. TIA
Created attachment 180425 [details] proposed fix v1.0 (small correction) + regression tests Just added brackets to make the meaning more clear
Patch looks good.
Released in HEAD for 3.7M3.
Thanks everyone.
Verified for 3.7M3 using I20101025-1602 (4.1 build)
*** Bug 342330 has been marked as a duplicate of this bug. ***