Skip to content

FEAT: Raise Unused code during build stage#130

Merged
Automation51D merged 5 commits into
mainfrom
feature/detect-unused-code
Jun 20, 2026
Merged

FEAT: Raise Unused code during build stage#130
Automation51D merged 5 commits into
mainfrom
feature/detect-unused-code

Conversation

@Jamesr51d

@Jamesr51d Jamesr51d commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Problem

Closes #84
Unused variables (and other unused declarations) were not being reported at
build time. The Java compiler already runs with -Xlint:all in this repo, but
-Xlint fundamentally cannot detect unused local variables, unused private
fields, unused private methods, or unused private parameters.

Example that went undetected: an unused Path tempPath local in
TestOnPremiseBuilder_CreateTempFile.

FIX: address compiler warnings:
Fix this-escape warning in MultiIPIDataCloud
Declare MultiIPIDataCloud final to resolve the "possible 'this' escape
before subclass is fully initialized" warning emitted by javac on JDK 21+

Replace java.util wildcard import in ValueTests with explicit imports
Expand import java.util.* to the four types the test actually uses
(ArrayList, Arrays, List, Map) in the shared module's ValueTests helper.

Uncomment -Werror to make sure no warning regressions are introduced.

Expected behaviour

Unused variables, methods, and similar dead declarations should be reported
during the build.

Change

Introduce PMD via maven-pmd-plugin in the parent
POM:

  • ci/pmd-ruleset.xml introduces a deliberately narrow ruleset:
    • unused local variables
    • unused private fields
    • unused private methods
    • unused private/constructor parameters
    • unnecessary (unused/duplicate) imports
  • pom.xml: maven-pmd-plugin added to the parent build (inherited by all
    four modules), bound to the compile phase with failOnViolation=true
    and includeTests=true. Unused code now surfaces during a normal build and
    fails it.
  • IPIntelligenceTests.java: fix the unused Path tempPath local exposed
    by the new check by asserting the temp data file is actually created.

Notes / scope

  • Because the gate fails the build, the first CI run may surface additional
    pre-existing unused-code violations beyond the one fixed here. These need to be
    cleaned up)for the build to go green.

Testing

  • XML well-formedness of pom.xml and ci/pmd-ruleset.xml validated locally.

The Java compiler's -Xlint cannot detect unused local variables, private
fields, private methods or private parameters.
Add the maven-pmd-plugin to the parent POM, bound to the compile phase with
failOnViolation=true, so these surface during a normal build and fail it.

Also fix the unused local it exposed in TestOnPremiseBuilder_CreateTempFile by
asserting the temp data file is actually created.
@Jamesr51d Jamesr51d requested a review from justadreamer June 17, 2026 15:25
Fix this-escape warning in MultiIPIDataCloud
Declare MultiIPIDataCloud final to resolve the "possible 'this' escape
before subclass is fully initialized" warning emitted by javac on JDK 21+

Replace java.util wildcard import in ValueTests with explicit imports
Expand `import java.util.*` to the four types the test actually uses
(ArrayList, Arrays, List, Map) in the shared module's ValueTests helper.

Uncomment -Werror to make sure no warning regressions are introduced.
@Jamesr51d

Copy link
Copy Markdown
Contributor Author

@justadreamer I've added some extra compiler warning fixes following the Java21 warnings issues on device-detection-java and pipeline-java

@Automation51D Automation51D merged commit e32c9e2 into main Jun 20, 2026
1 check passed
@Automation51D Automation51D deleted the feature/detect-unused-code branch June 20, 2026 05:28
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.

Compiler warnings

3 participants