Skip to content

Use pattern matching for instanceof - #1376

Merged
Frotty merged 1 commit into
masterfrom
pattern-matching-instanceof
Oct 7, 2026
Merged

Frotty merged 1 commit into
masterfrom
pattern-matching-instanceof

Conversation

@Frotty

@Frotty Frotty commented Oct 7, 2026

Copy link
Copy Markdown
Member

Applies Error Prone's PatternMatchingInstanceof suggestion to src/main, which is what floods the CI log with warnings.

Before After
PatternMatchingInstanceof warnings (compileJava) 913 0
Files changed 153

if (x instanceof Foo) { Foo f = (Foo) x; ... } becomes if (x instanceof Foo f) { ... }. No behaviour change.

The patch was generated with Error Prone's own fixer (-XepPatchChecks:PatternMatchingInstanceof -XepPatchLocation:IN_PLACE) and then cleaned up:

  • At 11 places the fixer declared the same binding twice in one scope, so the result did not compile (for example left instanceof ImIntVal v && right instanceof ImIntVal v). Those bindings are renamed by hand.
  • The fixer left whitespace-only lines where it deleted a cast declaration; they are removed.

How it was checked:

  • All 913 new bindings are scoped like the code they replace. I renamed each one inside its enclosing member and recompiled: a reference to a field or outer variable of the same name would then no longer resolve. It compiled, so no binding shadows anything.
  • 898 of the 913 tested variables are never reassigned after the test. The other 15 are Optional.get(), a field or a field access, and each is read once instead of twice.
  • compileJava and compileTestJava are clean. Tests are not touched (Error Prone is off for compileTestJava).
  • Run locally: LuaBackendAuditTests, OptimizerTests, GenericsTests, FieldIterationTests, DeterministicChecks, LuaKeyedMapTests, ClassesTests, BugTests, AutoCompleteTests, HoverTests, GetDefinitionTests. All 811 pass. Two BugTests failed once on a JGit index.lock race in the shared stdlib checkout and pass when run alone. CI runs the full suite.

This is a mass mechanical rewrite across 153 files, so open branches that touch the same lines will conflict; rebasing them is a matter of taking their side and re-running the fixer.

Applies Error Prone's PatternMatchingInstanceof suggestion to src/main
(913 warnings, 153 files). The patch declared the same binding twice in
one scope at 11 places, which did not compile; those are renamed by hand
and the blank lines the patch left behind are removed. No behaviour
change.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 7, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-07T11:26:13.919589Z 07bda51 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@Frotty
Frotty merged commit e301729 into master Oct 7, 2026
3 checks passed
@Frotty
Frotty deleted the pattern-matching-instanceof branch November 25, 2026 08:54
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.

1 participant