Skip to content

Fix the 37 SpotBugs findings and gate the build on all quality checks - #130

Merged
bertysentry merged 3 commits into
mainfrom
124-fix-spotbugs-findings
Jul 27, 2026
Merged

Fix the 37 SpotBugs findings and gate the build on all quality checks#130
bertysentry merged 3 commits into
mainfrom
124-fix-spotbugs-findings

Conversation

@bertysentry

Copy link
Copy Markdown
Contributor

What

Resolves every SpotBugs finding (closes #124) and — as requested — gates mvn verify on all four quality tools: a build now fails on any Checkstyle, PMD, CPD or SpotBugs finding.

Real fixes (correctness findings fixed, not suppressed)

  • ShellFileCopy.copyFile (NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE): Path.getFileName() returns null for a root path such as C:\; the method now rejects such paths with a clear IllegalArgumentException before any remote interaction. Covered by a new unit test.
  • WinRMSession (AT_STALE_THREAD_WRITE_OF_PRIMITIVE ×3, AT_NONATOMIC_64BIT_PRIMITIVE ×2): the mutable handshake state (negotiateFlags, signing keys, RC4 ciphers, authenticated) is now volatile — the session outlives individual operations and each operation runs on a fresh Utils.execute worker thread, so cross-thread visibility is required (accesses are sequential, never concurrent).
  • NtlmCrypto.encryptAndSign (VA_FORMAT_STRING_USES_NEWLINE): the OriginalContent header is now built by plain concatenation, making it obvious the protocol-mandated CRLF is a deliberate literal.
  • MD4.update (DLS_DEAD_LOCAL_STORE): removed the dead trailing curBufferPos store.
  • WqlQuery / WinRMWqlExecutor (EI_EXPOSE_REP/EI_EXPOSE_REP2): collection getters now return unmodifiable views and WinRMWqlExecutor copies the lists passed to its constructor. All internal callers only read these collections; the behavior change is documented in the README 2.x upgrade section.

Justified suppressions (@SuppressFBWarnings with stated reasons)

  • CipherGen (EI_EXPOSE_REP ×12, EI_EXPOSE_REP2): the upstream NTLM crypto port deliberately caches and returns its computed hashes/responses; defensive copies would churn the port for no security benefit. Member-level annotations (class-level triggered US_USELESS_SUPPRESSION_ON_CLASS) sharing one justification constant.
  • WinRMEndpoint (EI_EXPOSE_REP/EI_EXPOSE_REP2): the password char[] is deliberately shared so there is a single wipeable copy of the secret.
  • NTLMMessage / Type2Message / Type3Message / WinRMEndpoint (CT_CONSTRUCTOR_THROW): parse/validate-in-constructor is the upstream design; the NTLM message classes cannot be subclassed outside their package, so no finalizer-attack surface.

The new spotbugs-annotations dependency is provided-scope (compile-time only), so the library remains dependency-free at runtime.

Build gating

checkstyle:check, pmd:check, pmd:cpd-check and spotbugs:check are now bound to the verify phase, pinned to the exact versions/configs the site reports use (Checkstyle 3.6.0 + checkstyle.xml, PMD 3.26.0 + pmd.xml, CPD minimumTokens=50, SpotBugs 4.9.3.0), so the gates and the reports always agree.

Verification

  • target/spotbugsXml.xml: 0 bug instances; CPD, PMD and Checkstyle reports also at 0.
  • mvn verify site green on JDK 17 (like CI) with all four gates active: 80 unit tests + 1 IT pass.
  • Code formatted with mvn formatter:format.

🤖 Generated with Claude Code

Real fixes:
- ShellFileCopy.copyFile: guard against Path.getFileName() returning null
  for a root path (NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE), with a unit test
- WinRMSession: make the mutable handshake state volatile so writes on one
  per-call worker thread are visible to the next (AT_STALE_THREAD_WRITE_OF_PRIMITIVE,
  AT_NONATOMIC_64BIT_PRIMITIVE)
- NtlmCrypto: build the OriginalContent header by concatenation so the
  protocol-mandated CRLF is not a format string (VA_FORMAT_STRING_USES_NEWLINE)
- MD4.update: drop the dead trailing curBufferPos store (DLS_DEAD_LOCAL_STORE)
- WqlQuery/WinRMWqlExecutor: defensive copies and unmodifiable views for the
  collection getters (EI_EXPOSE_REP/EI_EXPOSE_REP2), documented in README

Justified suppressions (@SuppressFBWarnings with reasons):
- CipherGen: EI_EXPOSE_REP/EI_EXPOSE_REP2 on the upstream NTLM crypto port
- WinRMEndpoint: the password char[] is deliberately shared, not copied
- NTLMMessage/Type2Message/Type3Message/WinRMEndpoint: CT_CONSTRUCTOR_THROW,
  parse/validate-in-constructor is the upstream design

Build gating: mvn verify now fails on any Checkstyle, PMD, CPD or SpotBugs
finding (checkstyle:check, pmd:check, pmd:cpd-check, spotbugs:check bound to
the verify phase, pinned to the same versions as the site reports).

Closes #124

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 35668f60ff

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/main/java/org/metricshub/winrm/wql/WinRMWqlExecutor.java Outdated
Comment thread src/main/java/org/metricshub/winrm/WqlQuery.java Outdated
WinRMWqlExecutor now copies each result row (not just the outer list) and
returns rows that are unmodifiable down to the row level;
WqlQuery.getSubPropertiesMap() wraps each subproperty set unmodifiable too.
Both covered by new mutation tests.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@bertysentry

Copy link
Copy Markdown
Contributor Author

@codex please review again

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ec2a0de69e

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/test/java/org/metricshub/winrm/WqlQueryTest.java
license:update-file-header does not cover test sources; header added
manually, matching the other test files.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@bertysentry

Copy link
Copy Markdown
Contributor Author

@codex please review again

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. More of your lovely PRs please.

Reviewed commit: 68043c966b

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@bertysentry
bertysentry merged commit 113e01a into main Jul 27, 2026
5 checks passed
@bertysentry
bertysentry deleted the 124-fix-spotbugs-findings branch July 27, 2026 10:57
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.

Fix the 37 SpotBugs findings reported by the Maven site

1 participant