Skip to content

Conversation

@timtebeek
Copy link
Member

@timtebeek timtebeek commented Sep 27, 2025

Summary

  • Fixed the FinalClass recipe which was incorrectly making classes final even when they had nested static subclasses extending them
  • Removed unnecessary condition in excludeSupertypes() method that was preventing proper exclusion of supertypes

Description

The issue was in the excludeSupertypes() method which had a condition type.getOwningClass() != null that meant supertypes were only excluded when the extending class was nested. This was incorrect - we should exclude supertypes regardless of whether the extending class is nested or not.

Test plan

🤖 Generated with Claude Code

The FinalClass recipe was incorrectly attempting to make classes final even when they had nested static subclasses extending them. The issue was in the excludeSupertypes() method which had an unnecessary condition checking for type.getOwningClass() != null.

This condition meant that supertypes were only excluded when the extending class was nested, but we should exclude supertypes regardless of whether the extending class is nested or not.

Fixes #372

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
@github-project-automation github-project-automation bot moved this to In Progress in OpenRewrite Sep 27, 2025
@timtebeek timtebeek self-assigned this Sep 27, 2025
@timtebeek timtebeek marked this pull request as ready for review September 27, 2025 10:32
@timtebeek timtebeek added the bug Something isn't working label Sep 27, 2025
@timtebeek timtebeek merged commit 6d6fe5e into main Sep 27, 2025
2 checks passed
@timtebeek timtebeek deleted the fix-issue-372-final-class-nested-subclass branch September 27, 2025 10:33
@github-project-automation github-project-automation bot moved this from In Progress to Done in OpenRewrite Sep 27, 2025
mergify bot added a commit to robfrank/linklift that referenced this pull request Oct 15, 2025
… 2.18.0 to 2.19.0 [skip ci]

Bumps [org.openrewrite.recipe:rewrite-static-analysis](https://github.com/openrewrite/rewrite-static-analysis) from 2.18.0 to 2.19.0.
Release notes

*Sourced from [org.openrewrite.recipe:rewrite-static-analysis's releases](https://github.com/openrewrite/rewrite-static-analysis/releases).*

> 2.19.0
> ------
>
> What's Changed
> --------------
>
> * Fix FinalClass recipe to correctly handle nested static subclasses by [`@​timtebeek`](https://github.com/timtebeek) in [openrewrite/rewrite-static-analysis#742](https://redirect.github.com/openrewrite/rewrite-static-analysis/pull/742)
> * Add `Objects.requireNonNullElse/ElseGet` support to `AnnotateNullableParameters` by [`@​timtebeek`](https://github.com/timtebeek) in [openrewrite/rewrite-static-analysis#743](https://redirect.github.com/openrewrite/rewrite-static-analysis/pull/743)
> * Fix ReplaceLambdaWithMethodReference handling of nested class imports by [`@​timtebeek`](https://github.com/timtebeek) in [openrewrite/rewrite-static-analysis#745](https://redirect.github.com/openrewrite/rewrite-static-analysis/pull/745)
> * OpenRewrite recipe best practices by [`@​timtebeek`](https://github.com/timtebeek) in [openrewrite/rewrite-static-analysis#746](https://redirect.github.com/openrewrite/rewrite-static-analysis/pull/746)
> * Update recipe documentation examples by [`@​timtebeek`](https://github.com/timtebeek) in [openrewrite/rewrite-static-analysis#747](https://redirect.github.com/openrewrite/rewrite-static-analysis/pull/747)
> * Support for-each loop in NeedBraces by [`@​timtebeek`](https://github.com/timtebeek) in [openrewrite/rewrite-static-analysis#749](https://redirect.github.com/openrewrite/rewrite-static-analysis/pull/749)
> * Update documentation examples by [`@​timtebeek`](https://github.com/timtebeek) in [openrewrite/rewrite-static-analysis#750](https://redirect.github.com/openrewrite/rewrite-static-analysis/pull/750)
> * Update documentation examples by [`@​timtebeek`](https://github.com/timtebeek) in [openrewrite/rewrite-static-analysis#751](https://redirect.github.com/openrewrite/rewrite-static-analysis/pull/751)
> * fixed test that got changed behavior in rewrite-core by [`@​Jenson3210`](https://github.com/Jenson3210) in [openrewrite/rewrite-static-analysis#753](https://redirect.github.com/openrewrite/rewrite-static-analysis/pull/753)
> * No longer remove String.valueof when it's called on a method invocation by [`@​Laurens-W`](https://github.com/Laurens-W) in [openrewrite/rewrite-static-analysis#752](https://redirect.github.com/openrewrite/rewrite-static-analysis/pull/752)
>
> New Contributors
> ----------------
>
> * [`@​Jenson3210`](https://github.com/Jenson3210) made their first contribution in [openrewrite/rewrite-static-analysis#753](https://redirect.github.com/openrewrite/rewrite-static-analysis/pull/753)
>
> **Full Changelog**: <openrewrite/rewrite-static-analysis@v2.18.0...v2.19.0>


Commits

* [`3c1a313`](openrewrite/rewrite-static-analysis@3c1a313) No longer remove String.valueof when it's called on a method invocation ([#752](https://redirect.github.com/openrewrite/rewrite-static-analysis/issues/752))
* [`1d8d504`](openrewrite/rewrite-static-analysis@1d8d504) fixed test that got changed behavior in rewrite-core ([#753](https://redirect.github.com/openrewrite/rewrite-static-analysis/issues/753))
* [`504a582`](openrewrite/rewrite-static-analysis@504a582) Update documentation examples ([#751](https://redirect.github.com/openrewrite/rewrite-static-analysis/issues/751))
* [`cd26b74`](openrewrite/rewrite-static-analysis@cd26b74) Update documentation examples ([#750](https://redirect.github.com/openrewrite/rewrite-static-analysis/issues/750))
* [`b80e4b6`](openrewrite/rewrite-static-analysis@b80e4b6) Support for-each loop in NeedBraces ([#749](https://redirect.github.com/openrewrite/rewrite-static-analysis/issues/749))
* [`b93d869`](openrewrite/rewrite-static-analysis@b93d869) Update recipe documentation examples ([#747](https://redirect.github.com/openrewrite/rewrite-static-analysis/issues/747))
* [`7165caf`](openrewrite/rewrite-static-analysis@7165caf) OpenRewrite recipe best practices ([#746](https://redirect.github.com/openrewrite/rewrite-static-analysis/issues/746))
* [`eb91699`](openrewrite/rewrite-static-analysis@eb91699) Fix ReplaceLambdaWithMethodReference handling of nested class imports ([#745](https://redirect.github.com/openrewrite/rewrite-static-analysis/issues/745))
* [`a5d78d7`](openrewrite/rewrite-static-analysis@a5d78d7) Polish MoveFieldAnnotationToType
* [`0bd9340`](openrewrite/rewrite-static-analysis@0bd9340) Add `Objects.requireNonNullElse/ElseGet` support to `AnnotateNullableParamete...
* Additional commits viewable in [compare view](openrewrite/rewrite-static-analysis@v2.18.0...v2.19.0)
  
[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility\_score?dependency-name=org.openrewrite.recipe:rewrite-static-analysis&package-manager=maven&previous-version=2.18.0&new-version=2.19.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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

org.openrewrite.staticanalysis.FinalClass is wrong for nested sub classes

2 participants