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] UseCollectionIsEmpty can not detect the case foo.bar().size() #2542

Closed
wuchiuwong opened this issue May 26, 2020 · 1 comment · Fixed by #2899
Closed

[java] UseCollectionIsEmpty can not detect the case foo.bar().size() #2542

wuchiuwong opened this issue May 26, 2020 · 1 comment · Fixed by #2899
Labels
a:false-negative PMD doesn't flag a problematic piece of code
Milestone

Comments

@wuchiuwong
Copy link

Affects PMD Version:
6.22.0
Rule:
UseCollectionIsEmpty

Description:
UseCollectionIsEmpty can not detect the case foo.bar().size().
AST analyse result of the code sample:

<PrimaryPrefix FindBoundary='false' Image='' SingleLine='true' SuperModifier='false' ThisModifier='false'>
	<Name FindBoundary='false' Image='vr.getMembers' SingleLine='true' />
</PrimaryPrefix>
<PrimarySuffix ArgumentCount='0' Arguments='true' ArrayDereference='false' FindBoundary='false' Image='' SingleLine='true'>
    <Arguments ArgumentCount='0' FindBoundary='false' Image='' SingleLine='true' Size='0' />
</PrimarySuffix>
    <PrimarySuffix ArgumentCount='-1' Arguments='false' ArrayDereference='false' FindBoundary='false' Image='size' SingleLine='true' />
<PrimarySuffix ArgumentCount='0' Arguments='true' ArrayDereference='false' FindBoundary='false' Image='' SingleLine='true'>
    <Arguments ArgumentCount='0' FindBoundary='false' Image='' SingleLine='true' Size='0' />
</PrimarySuffix>

In the case vr.getMembers().size(), PrimaryPrefix is vr.getMembers, may cause error in comparing whether PrimaryPrefix is collection

Code Sample demonstrating the issue:

while (vr.getMembers().size() > 0)

Expected outcome:
false-negative

Running PMD through:
CLI

@wuchiuwong wuchiuwong added the a:bug PMD crashes or fails to analyse a file. label May 26, 2020
@oowekyala oowekyala added a:false-negative PMD doesn't flag a problematic piece of code and removed a:bug PMD crashes or fails to analyse a file. labels Oct 26, 2020
oowekyala added a commit to oowekyala/pmd that referenced this issue Nov 5, 2020
@oowekyala oowekyala added this to the 7.0.0 milestone Nov 10, 2020
@oowekyala oowekyala linked a pull request Nov 10, 2020 that will close this issue
5 tasks
@adangel
Copy link
Member

adangel commented Dec 11, 2020

Fixed via #2899 for PMD 7.

@adangel adangel closed this as completed Dec 11, 2020
@adangel adangel changed the title [java]UseCollectionIsEmpty can not detect the case foo.bar().size() [java] UseCollectionIsEmpty can not detect the case foo.bar().size() Jan 7, 2023
@adangel adangel mentioned this issue Jan 23, 2023
55 tasks
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
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants