Skip to content

infra: Enabling Spot-Bug in CircleCI#16665

Merged
romani merged 1 commit into
checkstyle:masterfrom
AmitKumarDeoghoria:spotbug
Apr 29, 2025
Merged

infra: Enabling Spot-Bug in CircleCI#16665
romani merged 1 commit into
checkstyle:masterfrom
AmitKumarDeoghoria:spotbug

Conversation

@AmitKumarDeoghoria

@AmitKumarDeoghoria AmitKumarDeoghoria commented Mar 26, 2025

Copy link
Copy Markdown
Contributor

Earlier Disabled : #14863
Due to SpotBug Issue Mentioned in :spotbugs/spotbugs-maven-plugin#806

Local Results on : mvn clean test-compile spotbugs
Screenshot 2025-03-27 at 1 16 18 AM

Most of the Bugs Flagged by SpotBugs are False Positives

For Example Lets Take This High-Confidence Error Flagges by SpotBug :
Screenshot 2025-04-01 at 11 29 13 PM
This is the part of the code where Error is Flagged :
Screenshot 2025-04-01 at 11 30 30 PM

What is the Error?

Ans:The error RCN_REDUNDANT_NULLCHECK_WOULD_HAVE_BEEN_A_NPE occurs because Spotbugs detects a redundant null check on a variable (stream in your code) that is guaranteed to be non-null due to prior dereferencing. In this case, this is likely a false positive caused by Spotbugs analyzing the bytecode generated for the try-with-resources block.

What’s happening:

-Files.find(...) returns a Stream, which will never be null (it throws IOException on failure).
-The try-with-resources block auto-closes the stream, and the generated bytecode includes an implicit if (stream != null) check to avoid closing a null resource. Spotbugs flags this as redundant because stream cannot logically be null here.

Why it’s a false positive:

The redundant check is in the bytecode (generated by try-with-resources), not our source code. Spotbugs is technically correct but overly strict here.

Solution

  • We have added all the false positives in the SpotBug-Exclusion List for now
  • We can hope that with newer version of spotbug and sb-contrib have less false positives.
  • we can Increase the threshold in config for spotbug from Low to Medium or High , In order to have less stricter checks.
    <threshold>Medium</threshold> [ But in this case we might miss out on some small actual bugs but the flase positives will be drastically reduced]

@AmitKumarDeoghoria

Copy link
Copy Markdown
Contributor Author

@romani can you review please. CI error is unrelated to the changes.

@AmitKumarDeoghoria

Copy link
Copy Markdown
Contributor Author

@romani Ping.

@romani romani left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Issue is closed, and about code covera

Items

Comment thread config/spotbugs-exclude.xml Outdated
<Class name="com.puppycrawl.tools.checkstyle.checks.sizes.RecordComponentNumberCheck"/>
<Bug pattern="AT_STALE_THREAD_WRITE_OF_PRIMITIVE"/>
</Match>
<!-- New Suppressions -->

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I am confused , why this violations appears?
It should be same as execution of mvn clean verify

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Hey @romani I suspect the difference arises because mvn verify runs later build phases that optimize/modify bytecode , while mvn test-compile spotbugs:check analyzes raw, unprocessed bytecode, exposing violations(e.g., redundant null checks) may be due to incomplete plugin/annotation processing.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Also I have referenced the Issue correctly now.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

ok, please analyze if this suppressins should stay forever, or we need to fix them in followup PRs.

@AmitKumarDeoghoria AmitKumarDeoghoria Apr 1, 2025

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Hey @romani , No need of fixing them, they should be there in the exclusion list until there is a newer version of spotbug with a fix for this flase positives. I analyzed some of the High Confidence Checks done by SpotBug, Almost all of them are false positives. I will give a example in Description to clarify why this is happening.

@romani romani Apr 13, 2025

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

please analyze all of them, if there is already defect, find link to it and place comment <!-- until .... -->
if issue not existing, please create and place same "until" comment.

please create issue on spotbugs plugin to get to know why validation by mvn clean verify is different from mvn spotbugs:check, already existing spotbugs/spotbugs-maven-plugin#806

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ok, we need to slice and dice current suppressions by :

  • Suppression until spotbug issue is fixed
  • point to improve in checkstyle codebase, separate issue.

We need enablement to be merged quicker to prevent new leaks of violations.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done. Apparently changes are needed in Build file which might lead to less false positives according to comment : spotbugs/spotbugs-maven-plugin#806 (comment). So until then we will suppress the false positives.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please remove <!-- New Suppressions --> line, it has no value

@AmitKumarDeoghoria AmitKumarDeoghoria changed the title Issue #806: Fixed False Positives in mvn clean test-compile spotbugs:… infra: Enabling Spot-Bug in CircleCI Mar 31, 2025
@romani

romani commented Apr 13, 2025

Copy link
Copy Markdown
Member

please change commit message to have prefix "infra:" , we reference issues in prefix only to our issue, not others, you can put link to spotbugs in commit message after prefix.
please do, to fix CI

@romani romani left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

see above.

@romani romani left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Items

Comment thread .circleci/config.yml
@AmitKumarDeoghoria AmitKumarDeoghoria force-pushed the spotbug branch 2 times, most recently from 15c7dad to 48f40e8 Compare April 28, 2025 20:05

@romani romani left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Last two items

Comment thread config/spotbugs-exclude.xml Outdated
</Match>

<!-- Suppress AFBR_ABNORMAL_FINALLY_BLOCK_RETURN -->
<!-- until https://github.com/spotbugs/spotbugs-maven-plugin/issues/806 -->

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please create new issue on checkstyle to fix all such violations.
Suppression file should have links to checkstyle issue until which suppression stays.
It will be separate activities to resolve them.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

Comment thread config/spotbugs-exclude.xml Outdated
<Class name="com.puppycrawl.tools.checkstyle.checks.sizes.RecordComponentNumberCheck"/>
<Bug pattern="AT_STALE_THREAD_WRITE_OF_PRIMITIVE"/>
</Match>
<!-- New Suppressions -->

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please remove <!-- New Suppressions --> line, it has no value

@romani

romani commented Apr 29, 2025

Copy link
Copy Markdown
Member

please recheck suppressions,
#16882

some already fixed.

@AmitKumarDeoghoria AmitKumarDeoghoria force-pushed the spotbug branch 2 times, most recently from 73affde to 2268b91 Compare April 29, 2025 14:10

@romani romani left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ok to merge.
Thanks a lot

@romani romani merged commit 583c718 into checkstyle:master Apr 29, 2025
115 of 116 checks passed
ayushactiveat added a commit to ayushactiveat/checkstyle that referenced this pull request Apr 6, 2026
ayushactiveat added a commit to ayushactiveat/checkstyle that referenced this pull request Apr 6, 2026
ayushactiveat added a commit to ayushactiveat/checkstyle that referenced this pull request Apr 6, 2026
ayushactiveat added a commit to ayushactiveat/checkstyle that referenced this pull request Apr 6, 2026
ayushactiveat added a commit to ayushactiveat/checkstyle that referenced this pull request Apr 6, 2026
ayushactiveat added a commit to ayushactiveat/checkstyle that referenced this pull request Apr 6, 2026
ayushactiveat added a commit to ayushactiveat/checkstyle that referenced this pull request Apr 6, 2026
ayushactiveat added a commit to ayushactiveat/checkstyle that referenced this pull request Apr 6, 2026
ayushactiveat added a commit to ayushactiveat/checkstyle that referenced this pull request Apr 6, 2026
ayushactiveat added a commit to ayushactiveat/checkstyle that referenced this pull request Apr 6, 2026
ayushactiveat added a commit to ayushactiveat/checkstyle that referenced this pull request Apr 6, 2026
ayushactiveat added a commit to ayushactiveat/checkstyle that referenced this pull request Apr 6, 2026
ayushactiveat added a commit to ayushactiveat/checkstyle that referenced this pull request Apr 6, 2026
ayushactiveat added a commit to ayushactiveat/checkstyle that referenced this pull request Apr 6, 2026
ayushactiveat added a commit to ayushactiveat/checkstyle that referenced this pull request Apr 6, 2026
ayushactiveat added a commit to ayushactiveat/checkstyle that referenced this pull request Apr 9, 2026
ayushactiveat added a commit to ayushactiveat/checkstyle that referenced this pull request Apr 9, 2026
ayushactiveat added a commit to ayushactiveat/checkstyle that referenced this pull request Apr 9, 2026
Malhar-M pushed a commit to Malhar-M/checkstyle that referenced this pull request Apr 19, 2026
Anushreebasics pushed a commit to Anushreebasics/checkstyle that referenced this pull request Apr 20, 2026
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