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] UseArrayListInsteadOfVector ignores Vector when other classes are imported #4148

Closed
ghost opened this issue Oct 11, 2022 · 2 comments · Fixed by #4156
Closed

[java] UseArrayListInsteadOfVector ignores Vector when other classes are imported #4148

ghost opened this issue Oct 11, 2022 · 2 comments · Fixed by #4156
Assignees
Labels
a:false-negative PMD doesn't flag a problematic piece of code
Milestone

Comments

@ghost
Copy link

ghost commented Oct 11, 2022

Affects PMD Version:6.47.0

Rule:UseArrayListInsteadOfVector

Please provide the rule name and a link to the rule documentation:
https://pmd.sourceforge.io/pmd-6.50.0/pmd_rules_java_performance.html#usearraylistinsteadofvector

Description:
Hi, I found a false negative about the rule UseArrayListInsteadOfVector, please read the first code example below. PMD should have reported a warning in line 5, but it does not. However, in the second code example, PMD can report the warning as expected. Hence, I think this is a false negative. Thank you!

Code Sample demonstrating the issue:

First code example

import org.Annotation;
@Annotation
public class C {
    void x() {
        Vector v = new Vector();  // should report a warning in this line, but no warnings
    }
}

Second code example

public class C {
    void x() {
        Vector v = new Vector();  // Can detect the warning
    }
}

Expected outcome:

PMD should report a violation at line 5, but doesn't. This is a false-negative.

Running PMD through: [Maven]

@ghost ghost added the a:false-negative PMD doesn't flag a problematic piece of code label Oct 11, 2022
@adangel adangel self-assigned this Oct 14, 2022
@adangel adangel added this to the 6.51.0 milestone Oct 14, 2022
@adangel adangel changed the title [java] UseArrayListInsteadOfVector should detect the method with annotation [java] UseArrayListInsteadOfVector ignores Vector when other classes are imported Oct 14, 2022
@adangel
Copy link
Member

adangel commented Oct 14, 2022

Thanks for the report.
It is not the Annotation, that trips the rule, but the other import, e.g. here we also don't detect Vector:

import some.OtherClass;

public class C {
    void x() {
        java.util.Vector v = new java.util.Vector();  // Can detect the warning
    }
}

Note: your example doesn't really compile, because you didn't import "java.util.Vector". As soon as you add import java.util.Vector; additionally, it works.

@ghost
Copy link
Author

ghost commented Oct 16, 2022

Hi, thanks for your reply. I may ignore the import when submitted the issue, and it seems that problem is not only casuse by the annotation and has been fixed now.

@ghost ghost closed this as completed Oct 16, 2022
This issue was closed.
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.

1 participant