Move violation comments above of annotated methods
#19803 opened on May 13, 2026
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
- Choose a Check (group of Inputs for same Check) from the list;
- Move all violation out of target code snippets;
- Remove related suppressions;
- Update violation line numbers inside unit test methods, if any changed.
- Send PR.
Notes
- Moving violating comments around requires adding
(X lines) above/belowto make sure they still reference the same line. You can refer to guide to specify violations for syntax. - 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