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

UnusedImports behaviour is different from documentation #3741

Closed
chao1995 opened this Issue Jan 19, 2017 · 2 comments

Comments

Projects
None yet
4 participants
@chao1995

chao1995 commented Jan 19, 2017

/var/tmp $ javac Test.java

No output.

/var/tmp $ cat Test.java

 // Doesn't warn - incorrect
import java.lang.String;

public class Test {
    private static final String SOMETHING = "a string";
}

/var/tmp $ cat config.xml

<?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">
    <module name="TreeWalker">
        <module name="UnusedImports" />
    </module>
</module>

/var/tmp $ java -jar checkstyle-7.4-all.jar -c config.xml Test.java

Starting audit...
Audit done.


Describe what you expect in detail.


As documented in the third item of UnusedImports description,

The class imported is from the java.lang package. For example importing java.lang.String.

I expect the import of java.lang.String to be reported as unused imports, however, it doesn't.

I'm aware there is a RedundantImport which can perform this check correctly, and in documentation it is just a proper subset of UnusedImport, so maybe this issue is just because of outdated documentation.

@MEZk

This comment has been minimized.

Show comment
Hide comment
@MEZk

MEZk Jan 19, 2017

Contributor

@romani
Please. assign.

The problem is due to the fact that we treat identifiers from java.lang package as references and add them into references list in processIdent method. I think all imports from java.lang should be treated as unused. In order to do this we can filter them in finishTree for example or earlier.

Contributor

MEZk commented Jan 19, 2017

@romani
Please. assign.

The problem is due to the fact that we treat identifiers from java.lang package as references and add them into references list in processIdent method. I think all imports from java.lang should be treated as unused. In order to do this we can filter them in finishTree for example or earlier.

MEZk added a commit to MEZk/checkstyle that referenced this issue Jan 22, 2017

MEZk added a commit to MEZk/checkstyle that referenced this issue Jan 22, 2017

MEZk added a commit to MEZk/checkstyle that referenced this issue Jan 22, 2017

MEZk added a commit to MEZk/checkstyle that referenced this issue Jan 22, 2017

MEZk added a commit to MEZk/checkstyle that referenced this issue Jan 22, 2017

MEZk added a commit to MEZk/checkstyle that referenced this issue Jan 22, 2017

MEZk added a commit to MEZk/checkstyle that referenced this issue Jan 22, 2017

rnveach added a commit that referenced this issue Jan 22, 2017

@rnveach

This comment has been minimized.

Show comment
Hide comment
@rnveach

rnveach Jan 22, 2017

Member

Fix is merged

Member

rnveach commented Jan 22, 2017

Fix is merged

@rnveach rnveach closed this Jan 22, 2017

@rnveach rnveach added this to the 7.5 milestone Jan 22, 2017

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