Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[java] BooleanGetMethodName: False-negatives with Boolean wrapper #5253

Closed
phansys opened this issue Oct 4, 2024 · 5 comments · Fixed by #5269
Closed

[java] BooleanGetMethodName: False-negatives with Boolean wrapper #5253

phansys opened this issue Oct 4, 2024 · 5 comments · Fixed by #5269
Labels
a:false-negative PMD doesn't flag a problematic piece of code an:enhancement An improvement on existing features / rules
Milestone

Comments

@phansys
Copy link

phansys commented Oct 4, 2024

Is your feature request related to a problem? Please describe.
Methods using Boolean return declaration are not managed by the BooleanGetMethodName rule.

Describe the solution you'd like
Update the rule to consider the Boolean wrapper too.

Describe alternatives you've considered
If this is considered as a BC break, I guess a property enabling the detection for the Boolean type could work.

Additional context

Boolean getFoo() {
    return true;
}

<![CDATA[
//MethodDeclaration
[starts-with(@Name, 'get')]
[@Arity = 0 or $checkParameterizedMethods = true()]
[ PrimitiveType[@Kind = 'boolean'] and @Overridden = false() ]
]]>

@phansys phansys added the an:enhancement An improvement on existing features / rules label Oct 4, 2024
@jsotuyod jsotuyod added the good first issue A great starting point for new contributors label Oct 4, 2024
@Aryant-Tripathi
Copy link
Contributor

Hello @phansys, I would like to work on this issue. I didn't get clarification on what we need to do here. Could you explain a little about what we need to perform here? I will be happy to do.

@phansys
Copy link
Author

phansys commented Oct 8, 2024

Hi @Aryant-Tripathi!

Could you explain a little about what we need to perform here?

The rule BooleanGetMethodName is catching cases like this:

boolean getFoo() {
    return true;
}

but isn't detecting any violation in cases like this:

Boolean getFoo() {
    return true;
}

Please, let me know if you need more context.
Thank you in advance.

@Aryant-Tripathi
Copy link
Contributor

@phansys sir, If possible may you be able to mark/tag PR as hacktoberfest-accepted / hacktoberfest label. It will help me in contributing a PR in hacktoberfest.

@phansys
Copy link
Author

phansys commented Oct 9, 2024

I haven't permission for that @Aryant-Tripathi, sorry.
Maybe @jsotuyod can help.

@jsotuyod
Copy link
Member

jsotuyod commented Oct 9, 2024

Sure, I've just added the hacktoberfest topic to the repo. Happy coding!

Aryant-Tripathi added a commit to Aryant-Tripathi/pmd that referenced this issue Oct 10, 2024
                - Updated XPath rule to include both  primitive and  wrapper class:
                  (PrimitiveType[@kind = 'boolean'] or ClassType[pmd-java:typeIs('java.lang.Boolean')])
                - Added test cases to ensure that methods returning  are also flagged correctly.
                - Ensured the rule enforces consistent method naming for both primitive and wrapper types.
@adangel adangel changed the title [java] [BooleanGetMethodName] Is there an explicit reason for not supporting Boolean wrapper class? [java] BooleanGetMethodName: False-negatives with Boolean wrapper Oct 11, 2024
@adangel adangel added the a:false-negative PMD doesn't flag a problematic piece of code label Oct 11, 2024
@adangel adangel added this to the 7.7.0 milestone Oct 11, 2024
@adangel adangel removed the good first issue A great starting point for new contributors label Oct 11, 2024
Aryant-Tripathi added a commit to Aryant-Tripathi/pmd that referenced this issue Oct 11, 2024
…Updated XPath rule to include both primitive and wrapper class:\n (PrimitiveType[@kind = 'boolean'] or ClassType[pmd-java:typeIs('java.lang.Boolean')])\n                - Added test cases to ensure that methods returning  are also flagged correctly.\n                - Ensured the rule enforces consistent method naming for both primitive and wrapper types.
Aryant-Tripathi added a commit to Aryant-Tripathi/pmd that referenced this issue Oct 11, 2024
…Updated XPath rule to include both primitive and wrapper class:\n (PrimitiveType[@kind = 'boolean'] or ClassType[pmd-java:typeIs('java.lang.Boolean')])\n                - Added test cases to ensure that methods returning  are also flagged correctly.\n                - Ensured the rule enforces consistent method naming for both primitive and wrapper types.
Aryant-Tripathi added a commit to Aryant-Tripathi/pmd that referenced this issue Oct 11, 2024
…Updated XPath rule to include both primitive and wrapper class:\n (PrimitiveType[@kind = 'boolean'] or ClassType[pmd-java:typeIs('java.lang.Boolean')])\n                - Added test cases to ensure that methods returning  are also flagged correctly.\n                - Ensured the rule enforces consistent method naming for both primitive and wrapper types.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a:false-negative PMD doesn't flag a problematic piece of code an:enhancement An improvement on existing features / rules
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants