Skip to content

[java] UnnecessaryImport false positive for on-demand imports in JavaDoc #2304

@kris-scheibe

Description

@kris-scheibe

Affects PMD Version:
6.21+
7.0.0

Rule: UnnecessaryImport

Description:
When an on-demand import is only used in a JavaDoc @link, @see or similar tag, the import is flagged.

This rule requires type-resolution to match the on-demand import, which isn't performed for JavaDoc content (I think...)

I already played around with this a little bit, but my solution seems like a hack, as I'm not sure, if the internal APIs were meant to be used that way and I feel that this might break easily if the code-resolution logic changes: kris-scheibe/pmd@3b19532

Do you guys have any ideas or comments?

Code Sample demonstrating the issue:

import java.util.*;

public class Foo {
    /**
     * {@link  ArrayList  arraylist}
     */
    public void test() {}
}

Running PMD through: Other

Metadata

Metadata

Assignees

No one assigned

    Labels

    a:false-positivePMD flags a piece of code that is not problematic

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions