#21726·checkstyle

EmptyLineSeparator: Inconsistent violation location for fields and methods with comments and Javadoc

Author: Praveen7294Created Sep 26, 2026Updated Sep 29, 2026
Labelsapproved

From #18811

EmptyLineSeparator reports violations at different locations for fields and methods depending on the type of comment associated with the definition.

The current behavior is inconsistent:

default field        -> 'VARIABLE_DEF'
default method       -> 'METHOD_DEF'
public/private field -> '/*'
public/private method -> '/*'
class definitions    -> always '/*'

The same variation can also be observed with different comment types, including single-line comments, multi-line comments, and javadoc comments.

Example

config_check.xml

<?xml version="1.0"?>
<!DOCTYPE module PUBLIC "-//Puppy Crawl//DTD Check Configuration 1.3//EN" 
"http://www.puppycrawl.com/dtds/configuration_1_3.dtd">

<module name="Checker">
  <module name="TreeWalker">
    <module name="EmptyLineSeparator">
      <property name="allowMultipleEmptyLines" value="false"/>
    </module>
  </module>
</module>

Test.java



/** Field docs. */
class Test {



    /** Field docs. */
    int value;


    /** Field docs. */
    public int value;

    
    /** Field docs. */
    private int value;

    
    /** Method docs. */
    void method() {}


    /** Method docs. */
    public void method1() {}


    /** Method docs. */
    private void method2() {}
    
}

logs

$ java -jar checkstyle-13.4.2-all.jar -c config_check.xml Test.java
Starting audit...
[ERROR] F:\GitHub\headhtmltagname\Test.java:3:1: '/*' has more than 1 empty lines before. [EmptyLineSeparator]
[ERROR] F:\GitHub\headhtmltagname\Test.java:9:5: 'VARIABLE_DEF' has more than 1 empty lines before. [EmptyLineSeparator]
[ERROR] F:\GitHub\headhtmltagname\Test.java:12:5: '/*' has more than 1 empty lines before. [EmptyLineSeparator]
[ERROR] F:\GitHub\headhtmltagname\Test.java:16:5: '/*' has more than 1 empty lines before. [EmptyLineSeparator]
[ERROR] F:\GitHub\headhtmltagname\Test.java:21:5: 'METHOD_DEF' has more than 1 empty lines before. [EmptyLineSeparator]
[ERROR] F:\GitHub\headhtmltagname\Test.java:24:5: '/*' has more than 1 empty lines before. [EmptyLineSeparator]
[ERROR] F:\GitHub\headhtmltagname\Test.java:28:5: '/*' has more than 1 empty lines before. [EmptyLineSeparator]
Audit done.
Checkstyle ends with 7 errors.

Expected behavior

The violation location should be consistent for fields and methods regardless of their modifiers or the type of comment preceding them.

Reporting the violation on the comment token (/*) would also make the locaiton consistent with the existing behvaior for other definitions and provide a more suitable location for automatic fixes.

This issue is intended to address the inconsistent violation location for fields and mehtods.