Skip to content

Add final modifiers everywhere, enforced by PMD - #13

Merged
diegourban merged 2 commits into
masterfrom
final-modifiers
Nov 6, 2026
Merged

diegourban merged 2 commits into
masterfrom
final-modifiers

Conversation

@diegourban

Copy link
Copy Markdown
Owner

Clean-code PR B of 4 (formatting ✅ → final → Javadoc → approved findings).

Commits

  1. 5c6d4e9 Add final: 872 modifiers across 108 files (library and problems).
    • Parameters: every one (Q2). No method anywhere reassigns a parameter, so none had to stay non-final (Q7).
    • Locals: every one that's never reassigned, including final var in problems and for-each variables (Q3).
    • Fields: those assigned once (Q4).
    • Classes: the 10 static-only classes (Q5).
    • How: OpenRewrite recipes (FinalizeMethodArguments, FinalizeLocalVariables, FinalizePrivateFields, FinalClass), plus for-each variables and a handful of parameters by hand.
    • Verified mechanically: with every final keyword and all whitespace removed, each file is identical to before (872 added, 0 removed).
  2. 418b1ce Enforce with PMD: config/pmd/final-modifiers.xml with four rules: MethodArgumentCouldBeFinal, LocalVariableCouldBeFinal, ImmutableField and ClassWithOnlyPrivateConstructorsShouldBeFinal.
    • maven-pmd-plugin 3.28.0 with PMD 7.29.0. pmd:check runs in verify over main and test sources and fails on any violation.
    • The "could be final" rules ignore variables that are reassigned, so a loop counter or accumulator is never flagged.
    • Checked that it fails: removing a single final makes ./mvnw verify fail ("PMD has found 1 violation").
    • Commit 1 is added to .git-blame-ignore-revs.

⚠️ Merge with a merge commit, so the .git-blame-ignore-revs hash stays valid.

Codacy (manual step for you)

In Codacy → algorithms-java → Code patterns → PMD, turn on the same four patterns so PR comments match the build:

  • Method Argument Could Be Final
  • Local Variable Could Be Final
  • Immutable Field
  • Class With Only Private Constructors Should Be Final

Test plan

  • ./mvnw verify: 591 tests, Spotless, PMD and coverage floors all pass
  • CI, Codacy, Codecov green

🤖 Generated with Claude Code

diegourban and others added 2 commits November 6, 2026 16:54
872 final modifiers added (OpenRewrite FinalizeMethodArguments,
FinalizeLocalVariables, FinalizePrivateFields and FinalClass, plus
for-each variables and a few parameters by hand). Nothing else changed:
with every final keyword and all whitespace removed, each file is
identical to before. No parameter is reassigned anywhere, so none had to
stay non-final.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
config/pmd/final-modifiers.xml enables MethodArgumentCouldBeFinal,
LocalVariableCouldBeFinal, ImmutableField and
ClassWithOnlyPrivateConstructorsShouldBeFinal; ./mvnw verify runs
pmd:check over main and test sources and fails on any violation. The
"could be final" rules ignore reassigned variables. The bulk final
commit is added to .git-blame-ignore-revs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.65%. Comparing base (ec46c94) to head (418b1ce).

Additional details and impacted files
@@            Coverage Diff            @@
##             master      #13   +/-   ##
=========================================
  Coverage     99.65%   99.65%           
  Complexity      279      279           
=========================================
  Files            24       24           
  Lines           576      576           
  Branches         94       94           
=========================================
  Hits            574      574           
  Partials          2        2           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 0 complexity · 8 duplication

Metric Results
Complexity 0
Duplication 8

View in Codacy

AI Reviewer: first review requested successfully. AI can make mistakes. Always validate suggestions.

Run reviewer

TIP This summary will be updated as you push new changes.

@codacy-production codacy-production Bot 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.

Pull Request Overview

✅ No blocking issues noticed

No blocking findings were identified. The remaining gap is that PMD enforcement scenarios are not covered by automated build or fixture tests, including verification for both production and test sources.

About this PR

  • Consider adding automated build-fixture or integration tests that verify each required final-modifier rule and confirm PMD runs against both production and test sources.

Test suggestions

  • Existing algorithm and data-structure behavior remains unchanged after modifier-only changes.
  • A missing final parameter is detected by the PMD build.
  • A missing final local variable is detected by the PMD build.
  • A missing final field is detected by the PMD build.
  • A static-only class made non-final is detected by the PMD build.
  • PMD enforcement applies to test sources as well as production sources.
Prompt proposal for missing tests
Consider implementing these tests if applicable:
1. A missing final parameter is detected by the PMD build.
2. A missing final local variable is detected by the PMD build.
3. A missing final field is detected by the PMD build.
4. A static-only class made non-final is detected by the PMD build.
5. PMD enforcement applies to test sources as well as production sources.

Make this review better

TIP Add a ticket key to the branch or title so the reviewer can check the PR against it. Or tell us which ticket tracker you use here.
TIP Add Codacy review.md instructions or an AGENTS.md so the reviewer knows your conventions.

TIP How was this review? Give us feedback


public static boolean isRectangleTriangle(double a, double b, double c) {
double[] array = new double[3];
public static boolean isRectangleTriangle(final double a, final double b, final double c) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 MEDIUM RISK

Suggestion: The two triangle helpers duplicate the array construction and sorting logic. Extract a private helper that returns the sorted sides, then reuse it in both methods to reduce maintenance risk.

See Clone in Codacy

TIP React 👍 if this review is right, or reply with what's wrong and how it could be better to help improve the reviewer.

@diegourban
diegourban merged commit 98bba13 into master Nov 6, 2026
2 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.

2 participants