Skip to content

[java] TooManyStaticImports: @SuppressWarnings("PMD.TooManyStaticImports") has stopped working #6737

Closed

Description

@altaiezior

Rule: TooManyStaticImports

Affects PMD Version: 7.25.0

Make sure, to test with the latest PMD version.

Description:

Earlier the @SuppressWarnings("PMD.TooManyStaticImports") used to work when defined over a class with the file having too many static imports but now it has stopped being honoured.

Steps to reproduce:

Please provide detailed steps for how we can reproduce the bug.

  1. Add a test class with too many static imports
  2. Try to suppress the warning by including suppress annotation over the class

Running PMD through: [CLI | Ant | Maven | Gradle | Designer | Other] maven

Activity

  1. added
    a:bug
    on May 30, 2026
  2. changed the title [-]@SuppressWarnings("PMD.TooManyStaticImports") has stopped working[/-] [+][java] TooManyStaticImports: @SuppressWarnings("PMD.TooManyStaticImports") has stopped working[/+] on May 30, 2026
  3. UncleOwen commented on May 30, 2026

    @UncleOwen
    Member

    Since 7.25.0 the location for some violations has been shrunk. Previously, TooManyStaticImports reported the whole file, now it only reports the last(!) import statement. See #6084 for details.

    Could you try adding //NOPMD to your last import statement?

  4. altaiezior commented on May 30, 2026

    @altaiezior
    Author

    @UncleOwen // NOPMD works but it was not on the last import but instead the first import as it currently the static import exception is reporting the failure at the first import and // NOPMD is to be added where the error is reported.

    However isn't NOPMD a little strict, because if there is anything else reporting for that line, it will also miss?

  5. altaiezior commented on May 30, 2026

    @altaiezior
    Author

    I just needed a rule where my test cases can resist more than 4 static imports, I believe if possible we should also make 10-15 as default for test classes

  6. UncleOwen commented on Jun 2, 2026

    @UncleOwen
    Member

    You could set the maximumStaticImports property to a higher value, or just not use this rule at all in your tests.

    A second ruleset for tests is common practice.

  7. added this to the 7.27.0 milestone on Jul 22, 2026
  8. added a commit that references this issue on Aug 2, 2026
    67e3c55
  9. added a commit that references this issue on Oct 7, 2026
    6254a4f
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:bug

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions