False negative in UnusedImportCheck
mahfouz72 opened this issue · comments
detected at #14548 (comment) and #14548 (comment)
I have read check documentation: https://checkstyle.sourceforge.io/checks/imports/unusedimports.html
I have downloaded the latest checkstyle from: https://checkstyle.org/cmdline.html#Download_and_Run
I have executed the cli and showed it below, as cli describes the problem better than 1,000 words
PS D:\test> cat src/Test.java
import java.util.List; // expected violation here but there is no violation
/**
* @link List // invalid link
*/
class Test{
}
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
"-//Puppy Crawl//DTD Check Configuration 1.3//EN"
"http://www.puppycrawl.com/dtds/configuration_1_3.dtd">
<module name="Checker">
<property name="charset" value="UTF-8"/>
<module name="TreeWalker">
<module name="UnusedImports"/>
</module>
</module>
PS D:\test> java -jar checkstyle-10.13.0-all.jar -c config.xml src/Test2.java
Starting audit...
Audit done.
Describe what you expect in detail.
This is an invalid Link because there is no { }
so the check should Ignore this and It shouldn't be considered as usage So we should have a violation on import java.util.List;
the reason for that may be because we use javadocUtil and this util is based on regular expression parsing not javadoc AST
another example:
/**
* @link {Collections::emptyEnumeration} // invalid link
*/
the above link also is considered a valid link as it has a valid tagName but it shouldn't be valid. for a method reference to be a valid link it has to be like this : @link {Collections#emptyEnumeration}