Skip to content

Conversation

@tobiasmelcher
Copy link
Contributor

@tobiasmelcher tobiasmelcher commented Jan 20, 2026

This PR fixes a NullPointerException that currently interrupts the code‑mining rendering pipeline. Due to this exception being thrown during editor initialization, no code minings are displayed when the editor is opened.

The problem is fixed by adding a null check for the support field in method call AbstractInlinedAnnotation.isInVisibleLines().

@github-actions
Copy link
Contributor

github-actions bot commented Jan 20, 2026

Test Results

 2 854 files   -   164   2 854 suites   - 164   2h 14m 12s ⏱️ - 15m 42s
 8 270 tests ±    0   8 019 ✅  -     3  251 💤 + 3  0 ❌ ±0 
22 120 runs   - 1 514  21 341 ✅  - 1 502  779 💤  - 12  0 ❌ ±0 

Results for commit c3bcdf0. ± Comparison against base commit 62f3974.

This pull request skips 3 tests.
AllUnitTests TestUnitWinRegistry ‑ testWinRegistry
JFaceTextTestSuite ContextInformationTest ‑ testContextInfo_hide_focusOut
org.eclipse.urischeme.internal.registration.TestUnitWinRegistry ‑ testWinRegistry

♻️ This comment has been updated with latest results.

@vogella
Copy link
Contributor

vogella commented Jan 20, 2026

Should viewer in the constructor maybe also assigned to fViewer? Without knowing to much about the code, it looks weird to me that viewer is passed to the constructor but ignored. Could that result in another NPE?

Suggested fix:

protected AbstractInlinedAnnotation(Position position, ISourceViewer viewer, ...) {
            super(TYPE, false, "");
           this.position = position;
           this.fViewer = viewer; // NEW NEW
            // ...
     }
 

@iloveeclipse iloveeclipse requested a review from Copilot January 20, 2026 19:24
@iloveeclipse
Copy link
Member

This PR fixes a NullPointerException that currently interrupts the code‑mining rendering pipeline

Steps to reproduce?

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a NullPointerException that prevents code minings from being displayed when an editor is initially opened. The issue occurs when isInVisibleLines() is called before the support field has been initialized via setSupport().

Changes:

  • Added null checks for the support field in both overloaded isInVisibleLines() methods
  • Returns true optimistically when support is not yet available, allowing annotations to be rendered during editor initialization

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@tobiasmelcher
Copy link
Contributor Author

This PR fixes a NullPointerException that currently interrupts the code‑mining rendering pipeline

Steps to reproduce?

Here the steps to reproduce the problem. Lars has already shown it in eclipse-jdt/eclipse.jdt.ui#2698 (comment).

  1. Enable all code minings for the java editor except "Only if there is at least one result" as shown in the next screenshot.
image 2. Open a Java editor with a source where the code minings should be visible. The code minings are initially not visible. They become visible when the source is modified. Here a screencast showing the problem scenario:
code_mining_in_java_editor.mp4

Following exception is thrown but not logged when opening the Java editor which stops the code mining to be rendered.

java.lang.NullPointerException: Cannot invoke "org.eclipse.jface.text.source.inlined.InlinedAnnotationSupport.isInVisibleLines(int)" because "this.support" is null
	at org.eclipse.jface.text.source.inlined.AbstractInlinedAnnotation.isInVisibleLines(AbstractInlinedAnnotation.java:254)
	at org.eclipse.jface.internal.text.codemining.CodeMiningLineHeaderAnnotation.isInVisibleLines(CodeMiningLineHeaderAnnotation.java:291)
	at org.eclipse.jface.internal.text.codemining.CodeMiningManager.lambda$13(CodeMiningManager.java:328)
	at java.base/java.util.Iterator.forEachRemaining(Iterator.java:133)
	at java.base/java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1939)
	at java.base/java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:762)
	at org.eclipse.jface.internal.text.codemining.CodeMiningManager.renderCodeMinings(CodeMiningManager.java:294)
	at org.eclipse.jface.internal.text.codemining.CodeMiningManager.lambda$1(CodeMiningManager.java:154)
	at java.base/java.util.concurrent.CompletableFuture$UniAccept.tryFire(CompletableFuture.java:718)
	at java.base/java.util.concurrent.CompletableFuture.postComplete(CompletableFuture.java:510)
	at java.base/java.util.concurrent.CompletableFuture.postFire(CompletableFuture.java:614)
	at java.base/java.util.concurrent.CompletableFuture$UniApply.tryFire(CompletableFuture.java:653)
	at java.base/java.util.concurrent.CompletableFuture$Completion.exec(CompletableFuture.java:483)
	at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:387)
	at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1312)
	at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1843)
	at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1808)
	at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:188)

@tobiasmelcher
Copy link
Contributor Author

tobiasmelcher commented Jan 21, 2026

Should viewer in the constructor maybe also assigned to fViewer? Without knowing to much about the code, it looks weird to me that viewer is passed to the constructor but ignored. Could that result in another NPE?

Suggested fix:

protected AbstractInlinedAnnotation(Position position, ISourceViewer viewer, ...) {
            super(TYPE, false, "");
           this.position = position;
           this.fViewer = viewer; // NEW NEW
            // ...
     }
 

You are right, this looks weird but is not the reason for the problem. Should I anyhow add the assignment this.fViewer = viewer; in the constructor?
I have added a stacktrace above showing where the problem is raised. I will update the pull request with a change which ensures that such kind of exceptions are visible in future.

@tobiasmelcher tobiasmelcher force-pushed the add_null_check_for_support_field branch from a81721f to 1c3ad70 Compare January 21, 2026 12:07
@iloveeclipse
Copy link
Member

Should I anyhow add the assignment this.fViewer = viewer; in the constructor?

No, this deserves extra fix, as the change will be much bigger.

Note: similar to the checks you've added for "support", similar checks must be added for the fViewer code and all callers of getTextWidget() & getViewer() have to be prepared for the "null" widgets.

@tobiasmelcher tobiasmelcher force-pushed the add_null_check_for_support_field branch from 1c3ad70 to 15cbafc Compare January 21, 2026 12:21
@tobiasmelcher
Copy link
Contributor Author

Should I anyhow add the assignment this.fViewer = viewer; in the constructor?

No, this deserves extra fix, as the change will be much bigger.

Note: similar to the checks you've added for "support", similar checks must be added for the fViewer code and all callers of getTextWidget() & getViewer() have to be prepared for the "null" widgets.

Ok @iloveeclipse , done with the latest push ([15cbafc]).

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@tobiasmelcher tobiasmelcher force-pushed the add_null_check_for_support_field branch from 15cbafc to 06851d8 Compare January 21, 2026 12:48
@vogella
Copy link
Contributor

vogella commented Jan 21, 2026

@iloveeclipse FYI - Gemini code review is in my opinion really good and free, it only needs to be enabled for a repo by the admin. If you start using AI code review you may want to have a look at it (for example by enabling it for your fork)

Gemini Code Review

@iloveeclipse
Copy link
Member

Could you please add this patch on top

diff --git a/bundles/org.eclipse.jface.text/src/org/eclipse/jface/text/codemining/ICodeMining.java b/bundles/org.eclipse.jface.text/src/org/eclipse/jface/text/codemining/ICodeMining.java
index 17831a6..15150ee 100644
--- a/bundles/org.eclipse.jface.text/src/org/eclipse/jface/text/codemining/ICodeMining.java
+++ b/bundles/org.eclipse.jface.text/src/org/eclipse/jface/text/codemining/ICodeMining.java
@@ -80,3 +80,3 @@
 	 *
-	 * @param viewer the viewer.
+	 * @param viewer the viewer, can be null
 	 * @param monitor the monitor.
diff --git a/bundles/org.eclipse.jface.text/src/org/eclipse/jface/text/source/inlined/AbstractInlinedAnnotation.java b/bundles/org.eclipse.jface.text/src/org/eclipse/jface/text/source/inlined/AbstractInlinedAnnotation.java
index c2df161..91dee7d 100644
--- a/bundles/org.eclipse.jface.text/src/org/eclipse/jface/text/source/inlined/AbstractInlinedAnnotation.java
+++ b/bundles/org.eclipse.jface.text/src/org/eclipse/jface/text/source/inlined/AbstractInlinedAnnotation.java
@@ -98,2 +98,3 @@
 		this.onMouseMove= onMouseMove;
+		this.fViewer= viewer;
 	}
@@ -164,5 +165,5 @@
 				ISourceViewer viewer= getViewer();
-				if (viewer instanceof ITextViewerExtension5) {
+				if (viewer instanceof ITextViewerExtension5 extViewer) {
 					// adjust offset according folded content
-					offset= ((ITextViewerExtension5) viewer).modelOffset2WidgetOffset(offset);
+					offset= extViewer.modelOffset2WidgetOffset(offset);
 				}

Add a null check for the `support` field in the
`AbstractInlinedAnnotation` class to prevent `NullPointerException` when
the `isInVisibleLines` method is called. This issue occurs because
`support` may not be initialized when the editor is first opened,
causing code minings to not render initially.
@tobiasmelcher tobiasmelcher force-pushed the add_null_check_for_support_field branch from 06851d8 to c3bcdf0 Compare January 21, 2026 15:38
@iloveeclipse iloveeclipse merged commit 5802a46 into eclipse-platform:master Jan 21, 2026
21 of 22 checks passed
@iloveeclipse
Copy link
Member

@tobiasmelcher : thanks.

@BeckerWdf BeckerWdf added this to the 4.39 M2 milestone Jan 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants