checkstyle/checkstyle

Move violation comments above of annotated methods

Open

#19803 opened on May 13, 2026

View on GitHub
 (3 comments) (0 reactions) (0 assignees)Java (8,005 stars) (8,668 forks)batch import
approvedgood first issuemiscellaneous

Description

Follow-up of https://github.com/checkstyle/checkstyle/issues/19757

Background

Find a way to fail build on cases of //violation .... usage in between of method javadoc java annotations and method signatures We should keep target code as natural as possible to not let violation comment to do side effect to violation and let users recognize problems as in real code and comment around just hint on what is wrong.

bad

/** 
 * This Javadoc contains unclosed tag.
 * <code>unclosed 'code' tag<code>
 */
 // violation 2 lines above 'Unclosed HTML tag found: <code>'
void foo() {}

good:

// violation 3 lines below 'Unclosed HTML tag found: <code>'
/** 
 * This Javadoc contains unclosed tag.
 * <code>unclosed 'code' tag<code>
 */
void foo() {}

bad

@Override
 // violation above 'xxx'
void foo() {}

good:

 // violation below 'xxx'
@Override
void foo() {}

Task

Ensure no violation comments in between of methods signature and annoation or javadoc all existing input files.

Here is a list of existing input files to be fixed: https://github.com/checkstyle/checkstyle/blob/876d99c33fc5af08b88a88db768dc7e40b351384/config/checkstyle-input-suppressions.xml#L143-L147

How to contribute

  1. Choose a Check (group of Inputs for same Check) from the list;
  2. Move all violation out of target code snippets;
  3. Remove related suppressions;
  4. Update violation line numbers inside unit test methods, if any changed.
  5. Send PR.

Notes

  1. Moving violating comments around requires adding (X lines) above/below to make sure they still reference the same line. You can refer to guide to specify violations for syntax.
  2. Make sure no input files exceed the limit of 120 lines.

Example of expected update https://github.com/checkstyle/checkstyle/pull/19804/changes , https://github.com/checkstyle/checkstyle/pull/19811

Contributor guide