Bug 552760 - NPE on JavaAnnotationImageProvider.getQuickFixErrorImage(): No Display
Summary: NPE on JavaAnnotationImageProvider.getQuickFixErrorImage(): No Display
Status: RESOLVED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 4.14   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: 4.14 M3   Edit
Assignee: Niko Stotz CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 547665
  Show dependency tree
 
Reported: 2019-11-06 16:26 EST by Niko Stotz CLA
Modified: 2020-01-30 02:15 EST (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Niko Stotz CLA 2019-11-06 16:26:26 EST
In bug 547665, I query IAnnotationAccessExtension.isPaintable() on a JavaMarkerAnnotation.
This might happen quite early, before JDT is completely initialized.
In this case, JavaPluginImages.getImageRegistry() creates a new ImageRegistry.
According to the constructor's javadoc, this is invalid, leading to an NPE downstream.

java.lang.NullPointerException
	at org.eclipse.jface.resource.JFaceResources.getResources(JFaceResources.java:213)
	at org.eclipse.jface.resource.ImageRegistry.<init>(ImageRegistry.java:150)
	at org.eclipse.jface.resource.ImageRegistry.<init>(ImageRegistry.java:122)
	at org.eclipse.jdt.internal.ui.JavaPluginImages.getImageRegistry(JavaPluginImages.java:669)
	at org.eclipse.jdt.internal.ui.JavaPluginImages.get(JavaPluginImages.java:626)
	at org.eclipse.jdt.internal.ui.javaeditor.JavaAnnotationImageProvider.getQuickFixErrorImage(JavaAnnotationImageProvider.java:100)
	at org.eclipse.jdt.internal.ui.javaeditor.JavaAnnotationImageProvider.getImage(JavaAnnotationImageProvider.java:155)
	at org.eclipse.jdt.internal.ui.javaeditor.JavaAnnotationImageProvider.getManagedImage(JavaAnnotationImageProvider.java:64)
	at org.eclipse.ui.texteditor.DefaultMarkerAnnotationAccess.getImage(DefaultMarkerAnnotationAccess.java:374)
	at org.eclipse.ui.texteditor.DefaultMarkerAnnotationAccess.isPaintable(DefaultMarkerAnnotationAccess.java:300)
	at org.eclipse.ui.internal.editors.text.codemining.annotation.AnnotationCodeMiningFilter.isPaintable(AnnotationCodeMiningFilter.java:110)
	at java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:174)
	at java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:175)
	at java.util.Spliterators$IteratorSpliterator.tryAdvance(Spliterators.java:1812)
	at java.util.stream.ReferencePipeline.forEachWithCancel(ReferencePipeline.java:126)
	at java.util.stream.AbstractPipeline.copyIntoWithCancel(AbstractPipeline.java:498)
	at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:485)
	at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)
	at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708)
	at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
	at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:499)
	at org.eclipse.ui.internal.editors.text.codemining.annotation.AnnotationCodeMiningProvider.createCodeMinings(AnnotationCodeMiningProvider.java:209)
	at org.eclipse.ui.internal.editors.text.codemining.annotation.AnnotationCodeMiningProvider.lambda$0(AnnotationCodeMiningProvider.java:183)
	at java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1590)
	at java.util.concurrent.CompletableFuture$AsyncSupply.exec(CompletableFuture.java:1582)
	at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
	at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
	at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
	at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)
Comment 1 Noopur Gupta CLA 2019-11-08 08:20:15 EST
What's your proposal to resolve this problem?
Comment 2 Niko Stotz CLA 2019-11-09 06:03:04 EST
(In reply to Noopur Gupta from comment #1)
> What's your proposal to resolve this problem?

What about:
At the beginning of org.eclipse.jdt.internal.ui.javaeditor.JavaAnnotationImageProvider.getImage(IJavaAnnotation, int)

Check if Display.getCurrent() is null and abort.

The upstream code seems to handle null results.
Comment 3 Andrey Loskutov CLA 2019-11-09 06:12:47 EST
(In reply to Niko Stotz from comment #2)
> (In reply to Noopur Gupta from comment #1)
> > What's your proposal to resolve this problem?
> 
> What about:
> At the beginning of
> org.eclipse.jdt.internal.ui.javaeditor.JavaAnnotationImageProvider.
> getImage(IJavaAnnotation, int)
> 
> Check if Display.getCurrent() is null and abort.
> 
> The upstream code seems to handle null results.

Please provide Gerrit.
Comment 4 Niko Stotz CLA 2019-11-18 14:59:51 EST
Gerrit: https://git.eclipse.org/r/#/c/152898/
Comment 6 Matthias Becker CLA 2020-01-29 08:22:57 EST
As this bug is fixed. Can we remove the workaround in AnnotationCodeMiningFilter#isPaintable


currently it catches NPEs like this:


	private boolean isPaintable(Annotation a) {
		// workaround for  https://bugs.eclipse.org/bugs/show_bug.cgi?id=552760
		// (NPE on JavaAnnotationImageProvider.getQuickFixErrorImage(): No Display)
		try {
			return annotationAccess.isPaintable(a);
		} catch (NullPointerException e) {
			return false;
		}
	}
Comment 7 Eclipse Genie CLA 2020-01-29 10:21:40 EST
New Gerrit change created: https://git.eclipse.org/r/156822