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

False negative in UnusedImportCheck #14697

Open
mahfouz72 opened this issue Mar 20, 2024 · 0 comments
Open

False negative in UnusedImportCheck #14697

mahfouz72 opened this issue Mar 20, 2024 · 0 comments
Labels

Comments

@mahfouz72
Copy link
Member

mahfouz72 commented Mar 20, 2024

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

if (JavadocTagInfo.isValidName(tag.getName())) {

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}
tag

@romani romani added the approved label Apr 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants