Use var for variables initialized with type casts#965
Merged
Conversation
MBoegers
approved these changes
Jan 13, 2026
Contributor
MBoegers
left a comment
There was a problem hiding this comment.
LGTM, great to see another edge case closed.
Member
Author
mergify bot
added a commit
to robfrank/linklift
that referenced
this pull request
Jan 25, 2026
…25.0 to 3.26.0 [skip ci] Bumps [org.openrewrite.recipe:rewrite-migrate-java](https://github.com/openrewrite/rewrite-migrate-java) from 3.25.0 to 3.26.0. Release notes *Sourced from [org.openrewrite.recipe:rewrite-migrate-java's releases](https://github.com/openrewrite/rewrite-migrate-java/releases).* > 3.26.0 > ------ > > What's Changed > -------------- > > * Also change managed dependency classifier to ehcache to avoid breaking multi module projects by [`@dsgrieve`](https://github.com/dsgrieve) in [openrewrite/rewrite-migrate-java#963](https://redirect.github.com/openrewrite/rewrite-migrate-java/pull/963) > * fix `IndexOutOfBoundsException` that occurs in `UseNoArgsConstructor` when visiting record compact constructor method by [`@zakaria-shahen`](https://github.com/zakaria-shahen) in [openrewrite/rewrite-migrate-java#964](https://redirect.github.com/openrewrite/rewrite-migrate-java/pull/964) > * Replace `getDisplayName()` and `getDescription()` methods with fields by [`@timtebeek`](https://github.com/timtebeek) in [openrewrite/rewrite-migrate-java#966](https://redirect.github.com/openrewrite/rewrite-migrate-java/pull/966) > * Use `var` for variables initialized with type casts by [`@timtebeek`](https://github.com/timtebeek) in [openrewrite/rewrite-migrate-java#965](https://redirect.github.com/openrewrite/rewrite-migrate-java/pull/965) > * Add recipe to find locale-sensitive date/time formatting affected by JDK 20+ CLDR changes by [`@timtebeek`](https://github.com/timtebeek) in [openrewrite/rewrite-migrate-java#967](https://redirect.github.com/openrewrite/rewrite-migrate-java/pull/967) > * Normalize version numbers in `FindJavaVersion` by [`@timtebeek`](https://github.com/timtebeek) in [openrewrite/rewrite-migrate-java#969](https://redirect.github.com/openrewrite/rewrite-migrate-java/pull/969) > * Fix JavaxWebXmlToJakartaWebXml regex to match multiline schemaLocation by [`@timtebeek`](https://github.com/timtebeek) in [openrewrite/rewrite-migrate-java#971](https://redirect.github.com/openrewrite/rewrite-migrate-java/pull/971) > > New Contributors > ---------------- > > * [`@dsgrieve`](https://github.com/dsgrieve) made their first contribution in [openrewrite/rewrite-migrate-java#963](https://redirect.github.com/openrewrite/rewrite-migrate-java/pull/963) > > **Full Changelog**: <openrewrite/rewrite-migrate-java@v3.25.0...v3.26.0> Commits * [`424b525`](openrewrite/rewrite-migrate-java@424b525) Fix JavaxWebXmlToJakartaWebXml regex to match multiline schemaLocation ([#971](https://redirect.github.com/openrewrite/rewrite-migrate-java/issues/971)) * [`4beeb8a`](openrewrite/rewrite-migrate-java@4beeb8a) Normalize version numbers in `FindJavaVersion` ([#969](https://redirect.github.com/openrewrite/rewrite-migrate-java/issues/969)) * [`1180190`](openrewrite/rewrite-migrate-java@1180190) [Auto] SDKMAN! Java candidates as of 2026-01-19T1023 * [`288ea96`](openrewrite/rewrite-migrate-java@288ea96) OpenRewrite recipe best practices * [`c7f8d21`](openrewrite/rewrite-migrate-java@c7f8d21) Replace `getEstimatedEffortPerOccurrence()` method with field * [`b22610d`](openrewrite/rewrite-migrate-java@b22610d) Replace `getTags()` method with field * [`90b4e63`](openrewrite/rewrite-migrate-java@90b4e63) Add recipe to find locale-sensitive date/time formatting affected by JDK 20+ ... * [`bb9adab`](openrewrite/rewrite-migrate-java@bb9adab) Update Gradle wrapper to 9.3.0 * [`da7c2e1`](openrewrite/rewrite-migrate-java@da7c2e1) Replace `Arrays.asList` with `List.of` in tests * [`7a52f88`](openrewrite/rewrite-migrate-java@7a52f88) OpenRewrite recipe best practices * Additional commits viewable in [compare view](openrewrite/rewrite-migrate-java@v3.25.0...v3.26.0) [](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. [//]: # (dependabot-automerge-start) [//]: # (dependabot-automerge-end) --- Dependabot commands and options You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot merge` will merge this PR after your CI passes on it - `@dependabot squash and merge` will squash and merge this PR after your CI passes on it - `@dependabot cancel merge` will cancel a previously requested merge and block automerging - `@dependabot reopen` will reopen this PR if it is closed - `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually - `@dependabot show ignore conditions` will show all of the ignore conditions of the specified dependency - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What's changed?
Added a new recipe with very limited scope in applying
varonly where initialized by a type cast within methods.What's your motivation?
This seemed like a simple and safe, non-controversial usage of
varthat we can then adopt in our tests, which frequently unpack and cast.Anything in particular you'd like reviewers to focus on?
Any edge cases where this might be unsafe?
Have you considered any alternatives or workarounds?
Could have also tackled static initializer blocks, but that seemed rare to me to have casts there.