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

UnusedImportsCheck does not detect parameter types in javadoc block tags #4606

Closed
silentj opened this Issue Jul 4, 2017 · 2 comments

Comments

Projects
None yet
2 participants
@silentj
Contributor

silentj commented Jul 4, 2017

/var/tmp $ javac InputUnusedImportWithBlockMethodParameters.java 
[no output]

/var/tmp $ cat InputUnusedImportWithBlockMethodParameters.java 
package com.puppycrawl.tools.checkstyle.checks.imports.unusedimports;

import java.util.Collection;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.TimeUnit;

public class InputUnusedImportWithBlockMethodParameters {

/**
 * @see ExecutorService#invokeAll(Collection, long, TimeUnit)
 */
    public int calculate() {
        return 0;
    }
}

/var/tmp $ cat config.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE module PUBLIC "-//Puppy Crawl//DTD Check Configuration 1.3//EN" "http://www.puppycrawl.com/dtds/configuration_1_3.dtd">
<module name="Checker">
  <module name="TreeWalker">
    <module name="UnusedImports">
      <property name="processJavadoc" value="true"/>
    </module>
  </module>
</module>

/var/tmp $ java -jar checkstyle-8.0-all.jar -c config.xml InputUnusedImportWithBlockMethodParameters.java 
Starting audit...
[ERROR] /private/var/tmp/InputUnusedImportWithBlockMethodParameters.java:3:8: Unused import - java.util.Collection. [UnusedImports]
[ERROR] /private/var/tmp/InputUnusedImportWithBlockMethodParameters.java:5:8: Unused import - java.util.concurrent.TimeUnit. [UnusedImports]
Audit done.
Checkstyle ends with 2 errors.

This should not be an error.

UnusedImportCheck fails to find Collection and TimeUnit in the javadoc. If these classes are unreferenced by the code, the imports are reported as unused.

This style works fine for inline javadoc tags ({@link ExecutorService#invokeAll(Collection, long, TimeUnit)}) but the difference in how block and inline tags are parsed means method parameter types aren't found for block tags.

silentj pushed a commit to silentj/checkstyle that referenced this issue Jul 4, 2017

silentj pushed a commit to silentj/checkstyle that referenced this issue Jul 6, 2017

silentj pushed a commit to silentj/checkstyle that referenced this issue Jul 8, 2017

@romani

This comment has been minimized.

Show comment
Hide comment
@romani

romani Jul 8, 2017

Member

type detection is not supported by Checkstyle(http://checkstyle.sourceforge.net/writingchecks.html#Limitations), we can not recognize types, we could match them only by string values, so all approaches will be error-prone. But at least we will generate less false-positives that annoy users more than false-negatives.

Member

romani commented Jul 8, 2017

type detection is not supported by Checkstyle(http://checkstyle.sourceforge.net/writingchecks.html#Limitations), we can not recognize types, we could match them only by string values, so all approaches will be error-prone. But at least we will generate less false-positives that annoy users more than false-negatives.

@romani romani added the approved label Jul 8, 2017

@checkstyle checkstyle deleted a comment from silentj Jul 8, 2017

@checkstyle checkstyle deleted a comment from silentj Jul 8, 2017

silentj pushed a commit to silentj/checkstyle that referenced this issue Jul 9, 2017

silentj pushed a commit to silentj/checkstyle that referenced this issue Jul 9, 2017

silentj pushed a commit to silentj/checkstyle that referenced this issue Jul 11, 2017

romani added a commit that referenced this issue Jul 11, 2017

@romani romani added the bug label Jul 11, 2017

@romani romani added this to the 8.1 milestone Jul 11, 2017

@romani

This comment has been minimized.

Show comment
Hide comment
@romani

romani Jul 11, 2017

Member

@silentj , thanks a lot for your updates, it is pleasure read your detailed PRs and good testing.

Member

romani commented Jul 11, 2017

@silentj , thanks a lot for your updates, it is pleasure read your detailed PRs and good testing.

@romani romani closed this Jul 11, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment