groovy

NPE in codecompletion if underlying type is null

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: 1.5
  • Fix Version/s: 1.5.2
  • Component/s: None
  • Labels:
    None
  • Patch Submitted:
    Yes
  • Number of attachments :
    1

Description

If you have code like these:

def tt

If you want use Autocompletion for the Object tt a NPE occurs:

Exception in thread "AutoAssist Delay" org.eclipse.swt.SWTException: Failed to execute runnable (java.lang.NullPointerException: Cannot invoke method getMethods() on null object)
at org.eclipse.swt.SWT.error(SWT.java:3563)
at org.eclipse.swt.SWT.error(SWT.java:3481)
at org.eclipse.swt.widgets.Synchronizer.syncExec(Synchronizer.java:178)
at org.eclipse.ui.internal.UISynchronizer.syncExec(UISynchronizer.java:118)
at org.eclipse.swt.widgets.Display.syncExec(Display.java:4097)
at org.eclipse.jface.text.contentassist.ContentAssistant$AutoAssistListener.showAssist(ContentAssistant.java:343)
at org.eclipse.jface.text.contentassist.ContentAssistant$AutoAssistListener.run(ContentAssistant.java:255)
at java.lang.Thread.run(Thread.java:619)
Caused by: java.lang.NullPointerException: Cannot invoke method getMethods() on null object
at org.codehaus.groovy.runtime.NullObject.invokeMethod(NullObject.java:77)
at org.codehaus.groovy.runtime.Invoker.invokePogoMethod(Invoker.java:103)
at org.codehaus.groovy.runtime.Invoker.invokeMethod(Invoker.java:79)
at org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:66)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodN(ScriptBytecodeAdapter.java:165)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethod0(ScriptBytecodeAdapter.java:193)
at org.codehaus.groovy.eclipse.core.types.impl.JavaElementCategoryLookup.mapCategory(JavaElementCategoryLookup.groovy:94)
at org.codehaus.groovy.eclipse.core.types.impl.JavaElementCategoryLookup.this$3$mapCategory(JavaElementCategoryLookup.groovy)
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.codehaus.groovy.runtime.metaclass.ReflectionMetaMethod.invoke(ReflectionMetaMethod.java:56)
at org.codehaus.groovy.runtime.MetaClassHelper.doMethodInvoke(MetaClassHelper.java:599)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:903)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodOnCurrentN(ScriptBytecodeAdapter.java:75)
at org.codehaus.groovy.eclipse.core.types.impl.JavaElementCategoryLookup.<init>(JavaElementCategoryLookup.groovy:30)
at org.codehaus.groovy.eclipse.codeassist.completion.GroovyCompletionProcessor.createMemberLookup(GroovyCompletionProcessor.java:195)
at org.codehaus.groovy.eclipse.codeassist.completion.CodeCompletionProcessor.computeCompletionProposals(CodeCompletionProcessor.java:110)
at org.codehaus.groovy.eclipse.editor.contentAssist.ContentAssistProcessorSet.computeCompletionProposals(ContentAssistProcessorSet.java:63)
at org.eclipse.jface.text.contentassist.ContentAssistant.computeCompletionProposals(ContentAssistant.java:1759)
at org.eclipse.jface.text.contentassist.CompletionProposalPopup.computeProposals(CompletionProposalPopup.java:478)
at org.eclipse.jface.text.contentassist.CompletionProposalPopup.access$16(CompletionProposalPopup.java:475)
at org.eclipse.jface.text.contentassist.CompletionProposalPopup$2.run(CompletionProposalPopup.java:410)
at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:67)
at org.eclipse.jface.text.contentassist.CompletionProposalPopup.showProposals(CompletionProposalPopup.java:404)
at org.eclipse.jface.text.contentassist.ContentAssistant$2.run(ContentAssistant.java:354)
at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:35)
at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:123)
at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.java:3659)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3296)
at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2389)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2353)
at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2219)
at org.eclipse.ui.internal.Workbench$4.run(Workbench.java:466)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:289)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:461)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:106)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:169)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:106)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:76)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:363)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:176)
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:508)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:447)
at org.eclipse.equinox.launcher.Main.run(Main.java:1173)
at org.eclipse.equinox.launcher.Main.main(Main.java:1148)

The error occurs at org.codehaus.groovy.eclipse.core.types.impl.JavaElementCategoryLookup.mapCategory(JavaElementCategoryLookup.groovy:94)
There isnt a Null-Check.
If you change

def methods = type.getMethods()

into

def methods = (!type)? []: type.getMethods()

all works fine again.

Activity

Hide
Thorsten Kamann added a comment -

Patch to resolve this issue. Please apply this inot the org.codehaus.groovy.eclipse.core project.

Show
Thorsten Kamann added a comment - Patch to resolve this issue. Please apply this inot the org.codehaus.groovy.eclipse.core project.
Hide
Aaron Tarter added a comment -

I cannot recreate this issue. completion on literal "null" works fine. Completion on:
def tt
tt.

Gives a different exception:

org.eclipse.swt.SWTException: Failed to execute runnable (java.lang.ClassCastException: org.codehaus.groovy.control.messages.SimpleMessage incompatible with org.codehaus.groovy.control.messages.ExceptionMessage)
at org.eclipse.swt.SWT.error(SWT.java:3563)
at org.eclipse.swt.SWT.error(SWT.java:3481)
at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:126)
at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.java:3659)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3296)
at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2389)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2353)
at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2219)
at org.eclipse.ui.internal.Workbench$4.run(Workbench.java:466)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:289)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:461)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:106)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:153)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:106)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:76)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:363)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:176)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:615)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:504)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:443)
at org.eclipse.equinox.launcher.Main.run(Main.java:1169)
at org.eclipse.equinox.launcher.Main.main(Main.java:1144)
Caused by: java.lang.ClassCastException: org.codehaus.groovy.control.messages.SimpleMessage incompatible with org.codehaus.groovy.control.messages.ExceptionMessage
at org.codehaus.groovy.eclipse.core.compiler.GroovyCompiler.mapFileNamesToExceptions(GroovyCompiler.java:401)
at org.codehaus.groovy.eclipse.core.compiler.GroovyCompiler.reportErrors(GroovyCompiler.java:372)
at org.codehaus.groovy.eclipse.core.compiler.GroovyCompiler.compile(GroovyCompiler.java:163)
at org.codehaus.groovy.eclipse.core.compiler.GroovyCompiler.compile(GroovyCompiler.java:88)
at org.codehaus.groovy.eclipse.core.types.TypeEvaluator.compileExpression(TypeEvaluator.java:172)
at org.codehaus.groovy.eclipse.core.types.TypeEvaluator.evaluate(TypeEvaluator.java:130)
at org.codehaus.groovy.eclipse.codeassist.completion.CodeCompletionProcessor.computeCompletionProposals(CodeCompletionProcessor.java:151)
at org.codehaus.groovy.eclipse.editor.contentAssist.ContentAssistProcessorSet.computeCompletionProposals(ContentAssistProcessorSet.java:63)
at org.eclipse.jface.text.contentassist.ContentAssistant.computeCompletionProposals(ContentAssistant.java:1758)
at org.eclipse.jface.text.contentassist.CompletionProposalPopup.computeProposals(CompletionProposalPopup.java:478)
at org.eclipse.jface.text.contentassist.CompletionProposalPopup.access$16(CompletionProposalPopup.java:475)
at org.eclipse.jface.text.contentassist.CompletionProposalPopup$2.run(CompletionProposalPopup.java:410)
at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:67)
at org.eclipse.jface.text.contentassist.CompletionProposalPopup.showProposals(CompletionProposalPopup.java:404)
at org.eclipse.jface.text.contentassist.ContentAssistant$2.run(ContentAssistant.java:354)
at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:35)
at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:123)
... 23 more

Show
Aaron Tarter added a comment - I cannot recreate this issue. completion on literal "null" works fine. Completion on: def tt tt. Gives a different exception: org.eclipse.swt.SWTException: Failed to execute runnable (java.lang.ClassCastException: org.codehaus.groovy.control.messages.SimpleMessage incompatible with org.codehaus.groovy.control.messages.ExceptionMessage) at org.eclipse.swt.SWT.error(SWT.java:3563) at org.eclipse.swt.SWT.error(SWT.java:3481) at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:126) at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.java:3659) at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3296) at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2389) at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2353) at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2219) at org.eclipse.ui.internal.Workbench$4.run(Workbench.java:466) at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:289) at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:461) at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149) at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:106) at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:153) at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:106) at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:76) at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:363) at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:176) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:615) at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:504) at org.eclipse.equinox.launcher.Main.basicRun(Main.java:443) at org.eclipse.equinox.launcher.Main.run(Main.java:1169) at org.eclipse.equinox.launcher.Main.main(Main.java:1144) Caused by: java.lang.ClassCastException: org.codehaus.groovy.control.messages.SimpleMessage incompatible with org.codehaus.groovy.control.messages.ExceptionMessage at org.codehaus.groovy.eclipse.core.compiler.GroovyCompiler.mapFileNamesToExceptions(GroovyCompiler.java:401) at org.codehaus.groovy.eclipse.core.compiler.GroovyCompiler.reportErrors(GroovyCompiler.java:372) at org.codehaus.groovy.eclipse.core.compiler.GroovyCompiler.compile(GroovyCompiler.java:163) at org.codehaus.groovy.eclipse.core.compiler.GroovyCompiler.compile(GroovyCompiler.java:88) at org.codehaus.groovy.eclipse.core.types.TypeEvaluator.compileExpression(TypeEvaluator.java:172) at org.codehaus.groovy.eclipse.core.types.TypeEvaluator.evaluate(TypeEvaluator.java:130) at org.codehaus.groovy.eclipse.codeassist.completion.CodeCompletionProcessor.computeCompletionProposals(CodeCompletionProcessor.java:151) at org.codehaus.groovy.eclipse.editor.contentAssist.ContentAssistProcessorSet.computeCompletionProposals(ContentAssistProcessorSet.java:63) at org.eclipse.jface.text.contentassist.ContentAssistant.computeCompletionProposals(ContentAssistant.java:1758) at org.eclipse.jface.text.contentassist.CompletionProposalPopup.computeProposals(CompletionProposalPopup.java:478) at org.eclipse.jface.text.contentassist.CompletionProposalPopup.access$16(CompletionProposalPopup.java:475) at org.eclipse.jface.text.contentassist.CompletionProposalPopup$2.run(CompletionProposalPopup.java:410) at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:67) at org.eclipse.jface.text.contentassist.CompletionProposalPopup.showProposals(CompletionProposalPopup.java:404) at org.eclipse.jface.text.contentassist.ContentAssistant$2.run(ContentAssistant.java:354) at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:35) at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:123) ... 23 more
Hide
Thorsten Kamann added a comment -

Hmm, this sounds very courious....

What OS and Eclipse version do you use?

Show
Thorsten Kamann added a comment - Hmm, this sounds very courious.... What OS and Eclipse version do you use?
Hide
Thorsten Kamann added a comment -

I have added the propsed null check. I dont think that this coul be a problem.

Show
Thorsten Kamann added a comment - I have added the propsed null check. I dont think that this coul be a problem.
Hide
Paul King added a comment -

close off release 1.5.4

Show
Paul King added a comment - close off release 1.5.4

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: