Skip to content

[java] New rule: OnDemandImport #7047

Closed

Description

@zbynek

Proposed Rule Name: OnDemandImport

Proposed Category: Best Practices

Description:
On-demand imports (also called star imports) should be use sparingly. By default, on-demand imports should be allowed only for static methods of supported test frameworks. These exclusions should be configurable by properties.

Related Checkstyle rule: https://checkstyle.sourceforge.io/checks/imports/avoidstarimport.html

Code Sample:

import static org.junit.jupiter.api.Assertions.* // this is allowed by default
import static java.lang.Math.*; // violation
import java.util.*; // violation

Possible Properties:

  • allowStaticImportsFrom -- set to * to allow all static imports, or a list of packages (default org.junit.jupiter.api,org.junit,org.testng)
  • allowTypeImportsFrom -- set to * to allow all type imports, or a list of packages (default empty)

Activity

  1. added
    a:new-rule
    on Sep 7, 2026
  2. suhanrain commented on Sep 8, 2026

    @suhanrain
    Contributor

    Hi, I'd like to work on this. I plan to follow the existing Java import-rule patterns and cover the default exclusions and both configurable properties with tests. Could you assign it to me?

  3. zbynek commented on Sep 8, 2026

    @zbynek
    ContributorAuthor

    @suhanrain thanks for offering to work on this -- I think there's no need to formally assign it, just stating your intent like you did should be enough.

  4. added this to the 7.28.0 milestone on Sep 10, 2026
  5. changed the title [-][java] new rule: OnDemandImport[/-] [+][java] New rule: OnDemandImport[/+] on Sep 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    a:new-rule

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions