Bug 553279 - [content assist] NullPointerException with postfix completions
Summary: [content assist] NullPointerException with postfix completions
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Text (show other bugs)
Version: 4.14   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: 4.14 RC1   Edit
Assignee: Roland Grunberg CLA
QA Contact: Roland Grunberg CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-11-20 11:52 EST by Pierre-Yves Bigourdan CLA
Modified: 2019-12-04 11:04 EST (History)
5 users (show)

See Also:
akurtakov: pmc_approved+


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Pierre-Yves Bigourdan CLA 2019-11-20 11:52:26 EST
I have enabled the completion, but the exception was thrown when I wasn't trying to explicitly trigger a postfix completion. I have not yet figured steps to reproduce the problem. Relevant stack trace:

java.lang.NullPointerException
	at org.eclipse.jdt.internal.ui.text.java.PostfixCompletionProposalComputer.updateTemplateEngine(PostfixCompletionProposalComputer.java:157)
	at org.eclipse.jdt.internal.ui.text.java.PostfixCompletionProposalComputer.analyzeCoreContext(PostfixCompletionProposalComputer.java:114)
	at org.eclipse.jdt.internal.ui.text.java.PostfixCompletionProposalComputer.computeCompletionEngine(PostfixCompletionProposalComputer.java:103)
	at org.eclipse.jdt.internal.ui.text.java.AbstractTemplateCompletionProposalComputer.computeCompletionProposals(AbstractTemplateCompletionProposalComputer.java:71)
	at org.eclipse.jdt.internal.ui.text.java.CompletionProposalComputerDescriptor.computeCompletionProposals(CompletionProposalComputerDescriptor.java:345)
	at org.eclipse.jdt.internal.ui.text.java.CompletionProposalCategory.computeCompletionProposals(CompletionProposalCategory.java:340)
	at org.eclipse.jdt.internal.ui.text.java.ContentAssistProcessor.collectProposals(ContentAssistProcessor.java:334)
	at org.eclipse.jdt.internal.ui.text.java.ContentAssistProcessor.computeCompletionProposals(ContentAssistProcessor.java:291)
	at org.eclipse.jface.text.contentassist.ContentAssistant$2.lambda$0(ContentAssistant.java:2015)
	at org.eclipse.jface.text.contentassist.ContentAssistant$2$$Lambda$1118.0000000019CFD820.accept(Unknown Source)
	at java.base/java.util.Collections$SingletonSet.forEach(Collections.java:4797)
	at org.eclipse.jface.text.contentassist.ContentAssistant$2.run(ContentAssistant.java:2014)
	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:45)
	at org.eclipse.jface.text.contentassist.ContentAssistant.computeCompletionProposals(ContentAssistant.java:2011)
	at org.eclipse.jface.text.contentassist.CompletionProposalPopup.computeProposals(CompletionProposalPopup.java:575)
	at org.eclipse.jface.text.contentassist.CompletionProposalPopup.lambda$0(CompletionProposalPopup.java:505)
	at org.eclipse.jface.text.contentassist.CompletionProposalPopup$$Lambda$1117.0000000019B7D620.run(Unknown Source)
	at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:72)
	at org.eclipse.jface.text.contentassist.CompletionProposalPopup.showProposals(CompletionProposalPopup.java:500)
	at org.eclipse.jface.text.contentassist.ContentAssistant$AutoAssistListener.lambda$0(ContentAssistant.java:380)
	at org.eclipse.jface.text.contentassist.ContentAssistant$AutoAssistListener$$Lambda$1115.0000000019CB7420.run(Unknown Source)
	at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:40)
	at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:185)
	at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.java:4145)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3812)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$5.run(PartRenderingEngine.java:1160)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:338)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:1049)
	at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:155)
	at org.eclipse.ui.internal.Workbench.lambda$3(Workbench.java:660)
	at org.eclipse.ui.internal.Workbench$$Lambda$107.0000000000000000.run(Unknown Source)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:338)
	at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:559)
	at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:150)
	at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:150)
	at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:203)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:137)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:107)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:401)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:255)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:567)
	at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:657)
	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:594)
	at org.eclipse.equinox.launcher.Main.run(Main.java:1465)
Comment 1 Andrey Loskutov CLA 2019-11-20 12:04:20 EST
The API of org.eclipse.jdt.core.dom.CompilationUnit.findDeclaringNode(String) says that it can return null, but the code doesn't check for null in PostfixCompletionProposalComputer.updateTemplateEngine(PostfixCompletionProposalComputer.java:157).

@Roland: the code is coming from bug 458804, so not a regression, but would be nice to fix in 4.14 RC1.
Comment 2 Roland Grunberg CLA 2019-11-20 12:09:27 EST
Yup, should be a simple null guard for the result of CompilationUnit#findDeclaringNode(..) .
Comment 3 Eclipse Genie CLA 2019-11-20 15:37:57 EST
New Gerrit change created: https://git.eclipse.org/r/153087
Comment 4 Roland Grunberg CLA 2019-11-20 15:39:35 EST
If you're able to find a way to reproduce it would be nice as we may be able to produce a testcase for it.
Comment 5 Pierre-Yves Bigourdan CLA 2019-11-21 08:55:38 EST
Okay, I think I've found a way to reproduce. 

* consider the following file (note the unused import):
import java.nio.file.Files;

public class Main {
    public static void main(String[] args) {
        Paths.
    }
}
* put your cursor at the end of the Paths. statement.
* trigger autocomplete.
* select the first option that appears, get(URI uri); this should give you Paths.get(null) with an additional 'java.nio.file.Paths' import.
* select all of get(null).
* trigger autocomplete.
* undo (Ctrl + Z or appropriate shortcut).
* the error should appear.
Comment 6 Roland Grunberg CLA 2019-11-22 12:09:57 EST
(In reply to Pierre-Yves B. from comment #5)
> Okay, I think I've found a way to reproduce. 
> 
> * consider the following file (note the unused import):
> import java.nio.file.Files;
> 
> public class Main {
>     public static void main(String[] args) {
>         Paths.
>     }
> }
> * put your cursor at the end of the Paths. statement.
> * trigger autocomplete.
> * select the first option that appears, get(URI uri); this should give you
> Paths.get(null) with an additional 'java.nio.file.Paths' import.
> * select all of get(null).
> * trigger autocomplete.
> * undo (Ctrl + Z or appropriate shortcut).
> * the error should appear.

In order to reproduce I had to specifically make sure that in the workspace preferences, under Java -> Editor -> Content Assist, 'Fill method arguments and show guessed arguments' was enabled, and also set to 'Insert best guessed arguments'.

Also, I noticed that even with postfix completion entirely disabled, performing your exact instructions still breaks the syntax highlighting (all text becomes black) in the editor, so there may still be a bug. Can you confirm this also ?
Comment 7 Pierre-Yves Bigourdan CLA 2019-11-22 16:57:53 EST
(In reply to Roland Grunberg from comment #6) 
> Also, I noticed that even with postfix completion entirely disabled,
> performing your exact instructions still breaks the syntax highlighting (all
> text becomes black) in the editor, so there may still be a bug. Can you
> confirm this also ?

I did notice that as well, though it does not seem to happen systematically with my setup, only occasionally.
Comment 8 Roland Grunberg CLA 2019-11-25 10:28:49 EST
I would propose pushing the current fix in as it is the right thing to do. We can create a testcase afterwards if possible and I'll file a bug for the additional issue discussed in comment #6 and #7 .
Comment 10 Roland Grunberg CLA 2019-11-25 13:21:25 EST
I'll file a separate bug for issues mentioned here that are reproducible even without postfix completion enabled.
Comment 11 Roland Grunberg CLA 2019-12-04 11:04:14 EST
Verified for 4.14 RC1 using I20191204-0600 build.