Skip to content

Issue #18599: Resolve error-prone violations for ObjectEqualsForPrimi…#18625

Closed
VinishaWagh wants to merge 1 commit into
checkstyle:masterfrom
VinishaWagh:errorProne
Closed

Issue #18599: Resolve error-prone violations for ObjectEqualsForPrimi…#18625
VinishaWagh wants to merge 1 commit into
checkstyle:masterfrom
VinishaWagh:errorProne

Conversation

@VinishaWagh

@VinishaWagh VinishaWagh commented Jan 12, 2026

Copy link
Copy Markdown
Contributor

Issue : #18599

https://errorprone.info/bugpattern/ObjectEqualsForPrimitives

This PR handles the violations related to ObjectEqualsForPrimitives for the given files:

LineColumn.java

Violation.java

SuppressWithNearbyCommentFilter.java

SuppressWithPlainTextCommentFilter.java

SuppressionCommentFilter.java

@VinishaWagh

VinishaWagh commented Jan 12, 2026

Copy link
Copy Markdown
Contributor Author

Hello @romani
for warning in Violation.java, when changed showed error Overly complex boolean expression because equals method combines 11 conditions using &&

final Violation violation = (Violation) object;
return Objects.equals(lineNo, violation.lineNo)
                && Objects.equals(columnNo, violation.columnNo)
                && Objects.equals(columnCharIndex, violation.columnCharIndex)
                && Objects.equals(tokenType, violation.tokenType)
                && Objects.equals(severityLevel, violation.severityLevel)
                && Objects.equals(moduleId, violation.moduleId)
                && Objects.equals(key, violation.key)
                && Objects.equals(bundle, violation.bundle)
                && Objects.equals(sourceClass, violation.sourceClass)
                && Objects.equals(customMessage, violation.customMessage)
                && Arrays.equals(args, violation.args);

to:

final Violation violation = (Violation) object;
return lineNo == violation.lineNo
                && columnNo == violation.columnNo
                && columnCharIndex == violation.columnCharIndex
                && tokenType == violation.tokenType
                && Objects.equals(severityLevel, violation.severityLevel)
                && Objects.equals(moduleId, violation.moduleId)
                && Objects.equals(key, violation.key)
                && Objects.equals(bundle, violation.bundle)
                && Objects.equals(sourceClass, violation.sourceClass)
                && Objects.equals(customMessage, violation.customMessage)
                && Arrays.equals(args, violation.args);

Should we suppress this error?

@Pankraz76

Pankraz76 commented Jan 12, 2026

Copy link
Copy Markdown

plz activate ObjectEqualsForPrimitives as error if fixed.

like seen in:

@VinishaWagh

Copy link
Copy Markdown
Contributor Author

@Pankraz76
Violation.java is still left to be resolved... which is why I didn't activate it...
But once I get the next command, I'll surely add it...

Pankraz76 pushed a commit to Pankraz76/checkstyle that referenced this pull request Jan 12, 2026
Pankraz76 pushed a commit to Pankraz76/checkstyle that referenced this pull request Jan 12, 2026
Pankraz76 pushed a commit to Pankraz76/checkstyle that referenced this pull request Jan 12, 2026
Pankraz76 pushed a commit to Pankraz76/checkstyle that referenced this pull request Jan 12, 2026
Pankraz76 pushed a commit to Pankraz76/checkstyle that referenced this pull request Jan 12, 2026
Pankraz76 pushed a commit to Pankraz76/checkstyle that referenced this pull request Jan 12, 2026
Pankraz76 pushed a commit to Pankraz76/checkstyle that referenced this pull request Jan 13, 2026
Pankraz76 pushed a commit to Pankraz76/checkstyle that referenced this pull request Jan 13, 2026
Pankraz76 pushed a commit to Pankraz76/checkstyle that referenced this pull request Jan 13, 2026
Pankraz76 pushed a commit to Pankraz76/checkstyle that referenced this pull request Jan 13, 2026
Pankraz76 pushed a commit to Pankraz76/checkstyle that referenced this pull request Jan 13, 2026

@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.

How to configure error prone to not do violations on n equals implementations ?
Such methods are generated.

@VinishaWagh VinishaWagh force-pushed the errorProne branch 2 times, most recently from db026ce to 14367de Compare January 14, 2026 08:43
Pankraz76 pushed a commit to Pankraz76/checkstyle that referenced this pull request Jan 14, 2026
Pankraz76 pushed a commit to Pankraz76/checkstyle that referenced this pull request Jan 14, 2026
@VinishaWagh

VinishaWagh commented Jan 14, 2026

Copy link
Copy Markdown
Contributor Author

How to configure error prone to not do violations on n equals implementations ? Such methods are generated.

@romani
I am still figuring out, but I did suppress the warning and the build is now success in local...
Please have a look...

@romani

romani commented Jan 15, 2026

Copy link
Copy Markdown
Member

Suppression
Suppress false positives by adding the suppression annotation @SuppressWarnings("ObjectEqualsForPrimitives") to the enclosing element.

Please apply such annotation to all case, for now all items are wont fix, technically should be fixed, but this code is generated, so consistency is more critical.

Pankraz76 pushed a commit to Pankraz76/checkstyle that referenced this pull request Jan 15, 2026
Pankraz76 pushed a commit to Pankraz76/checkstyle that referenced this pull request Jan 15, 2026
Pankraz76 pushed a commit to Pankraz76/checkstyle that referenced this pull request Jan 15, 2026
Pankraz76 pushed a commit to Pankraz76/checkstyle that referenced this pull request Jan 15, 2026
Pankraz76 pushed a commit to Pankraz76/checkstyle that referenced this pull request Jan 15, 2026
Pankraz76 pushed a commit to Pankraz76/checkstyle that referenced this pull request Jan 15, 2026

@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.

please rebase and :

&& Objects.equals(columnNo, violation.columnNo)
&& Objects.equals(columnCharIndex, violation.columnCharIndex)
&& Objects.equals(tokenType, violation.tokenType)
// -@cs[BooleanExpressionComplexity] equals - a lot of fields to check.

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 move suppression to https://github.com/checkstyle/checkstyle/blob/master/config/suppressions-xpath.xml
please do same for // -@cs[CyclomaticComplexity] equals - a lot of fields to check.

@romani

romani commented Jan 16, 2026

Copy link
Copy Markdown
Member

please supppress:

<problems is_local_tool="true">
<problem>
<file>
file://$PROJECT_DIR$/src/main/java/com/puppycrawl/tools/checkstyle/api/Violation.java
</file>
<line>371</line>
<module>project</module>
<package>com.puppycrawl.tools.checkstyle.api</package>
<entry_point TYPE="method" FQNAME="com.puppycrawl.tools.checkstyle.api.Violation boolean equals(java.lang.Object object)"/>
<problem_class id="OverlyComplexBooleanExpression" severity="ERROR" attribute_key="ERRORS_ATTRIBUTES">Overly complex boolean expression</problem_class>
<description>Overly complex boolean expression (11 terms) #loc</description>
<highlighted_element>
lineNo == violation.lineNo && columnNo == violation.columnNo && colu...
</highlighted_element>
<language>JAVA</language>
<offset>15</offset>
<length>643</length>
</problem>
</problems>

thee is no configuration to exclude such methods:
image

@VinishaWagh

Copy link
Copy Markdown
Contributor Author

Okay, I am on it!

@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

* @noinspectionreason EqualsCalledOnEnumConstant - enumeration is needed to keep
* code consistent
* @noinspection ObjectEqualsForPrimitives
* @noinspectionreason ObjectEqualsForPrimitives - this code is generated

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.

Something is broken here
We do -Xep:ObjectEqualsForPrimitives:ERROR
And now we need suppression of Idea inspection in such places

@Brijeshthummar02

Copy link
Copy Markdown
Contributor

@VinishaWagh the ObjectEqualsForPrimitives is already been fixed , and merged.
You can close the PR.

@romani romani closed this Feb 16, 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.

4 participants