Skip to content

Remove unreachable null guard in ViewerState.updateSelection() - #4506

Merged
HeikoKlare merged 1 commit into
eclipse-platform:masterfrom
vlakn:remove_viewerstate_null_guard
Oct 16, 2026
Merged

HeikoKlare merged 1 commit into
eclipse-platform:masterfrom
vlakn:remove_viewerstate_null_guard

Conversation

@vlakn

@vlakn vlakn commented Oct 16, 2026

Copy link
Copy Markdown
Contributor

Follow-up to #4426, as discussed in this review comment.

What

Removes the selections == null branch from TextViewer.ViewerState.updateSelection().

Why

The branch is never reached:

  • updateSelection() has a single caller, setSelectedRanges(), which passes Arrays.stream(...).toArray(Position[]::new). That's never null, at most an empty array.
  • An empty array already goes through the regular else branch.
  • ViewerState is a private inner class of TextViewer. No other code can call this method.

No behavior change.

updateSelection() has a single caller, setSelectedRanges(), which always
passes an array created by Arrays.stream(...).toArray(). The argument is
never null. ViewerState is a private inner class of TextViewer, so no
other caller exists.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

The sole caller guarantees a non-null array, so the cleanup preserves existing behavior.

0 open findings

What changed in this PR

Removes an unreachable null guard from JFace’s selection tracking, following up on #4426 without changing behavior.

Changes:

  • Removes the null-array branch from ViewerState.updateSelection().
  • Preserves handling of empty and populated selection arrays.
File Description
bundles/​org.eclipse.jface.text/​src/​org/​eclipse/​jface/​text/​TextViewer.java Removes the unreachable selection null guard.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@github-actions

Copy link
Copy Markdown
Contributor

Test Results

   867 files  ±0     867 suites  ±0   54m 23s ⏱️ +32s
 8 463 tests ±0   8 221 ✅ ±0  242 💤 ±0  0 ❌ ±0 
21 267 runs  ±0  20 584 ✅ ±0  683 💤 ±0  0 ❌ ±0 

Results for commit eb6c5e0. ± Comparison against base commit 2738b40.

@HeikoKlare HeikoKlare left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thank you for that reasonable cleanup. With only a single caller that already properly ensures a non-null argument, it is not necessary to have explicit handling for it in the called method as well. Otherwise, a similar adaptation for this case like done in #4426 would be necessary here, which is obsolete as the code is never called.

@HeikoKlare
HeikoKlare merged commit 1bed3dc into eclipse-platform:master Oct 16, 2026
18 checks passed
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.

3 participants