Skip to content

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

Closed

Description

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]

Activity

  1. ghost added
    a:false-negative
    on Oct 11, 2022
  2. self-assigned this
    on Oct 14, 2022
  3. added this to the 6.51.0 milestone on Oct 14, 2022
  4. changed the title [-][java] UseArrayListInsteadOfVector should detect the method with annotation[/-] [+][java] UseArrayListInsteadOfVector ignores Vector when other classes are imported[/+] on Oct 14, 2022
  5. adangel commented on Oct 14, 2022

    @adangel
    Member

    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.

  6. added a commit that references this issue on Oct 14, 2022
    78a4917
  7. ghost closed this as completedon Oct 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

a:false-negative

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions