Skip to content

RedundantImport does not work with module imports #18171

@stoyanK7

Description

@stoyanK7

Part of issue


I have read check documentation: https://checkstyle.org/checks/imports/redundantimport.html#RedundantImport
I am using the latest checkstyle generated from the master branch via mvn clean package -Passembly
I have executed the CLI and showed it below, as CLI describes the problem better than 1,000 words

$ javac -version
javac 25.0.1

$ javac Test.java
# no output as expected

$ cat config.xml
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
  "-//Puppy Crawl//DTD Check Configuration 1.3//EN"
  "https://checkstyle.org/dtds/configuration_1_3.dtd">
<module name="Checker">
  <module name="TreeWalker">
    <module name="RedundantImport"/>
  </module>
</module>

$ cat Test.java
import module java.base;
import module java.base;  // I expect violation here, but there is none.

class Test {
}

$ RUN_LOCALE="-Duser.language=en -Duser.country=US"
$ java $RUN_LOCALE -jar checkstyle-12.2.0-SNAPSHOT-all.jar -c config.xml Test.java
Starting audit...
Audit done.

I expect to see an error that tells me that I have a redundant import java.base. Something like:

[ERROR] /tmp/Test.java:2:1: Duplicate import to line 1 - java.base [RedundantImport]

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions