OneStatementPerLine is affected by annotation
Author: sarser2048Created Feb 24, 2023Updated Sep 27, 2026
Labelsapprovedgoogle stylefalse negative
I have read check documentation: https://checkstyle.sourceforge.io/config_coding.html#OneStatementPerLine I have downloaded the latest checkstyle from: https://checkstyle.org/cmdline.html#Download_and_Run I have executed the cli and showed it below, as cli describes the problem better than 1,000 words
/var/tmp $ javac Main.java
/var/tmp $ cat config.xml
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
"-//Checkstyle//DTD Checkstyle Configuration 1.3//EN"
"https://checkstyle.org/dtds/configuration_1_3.dtd">
<module name="Checker">
<property name="severity" value="error"/>
<property name="fileExtensions" value="java, properties, xml"/>
<module name="TreeWalker">
<module name="OneStatementPerLine"/>
</module>
</module>
/var/tmp $ cat Main.java
public class Main {
String str = "123";
; // report a OneStatementPerLine warning here
@MyAnnotation
String str = "123";
; // no OneStatementPerLine Warning
}
/var/tmp $ RUN_LOCALE="-Duser.language=en -Duser.country=US"
/var/tmp $ java $RUN_LOCALE -jar checkstyle-10.3.3-all.jar -c config.xml YOUR_FILE.java
Starting audit...
[ERROR] /path/tofile:3:3: Only one statement per line allowed. [OneStatementPerLine]
Audit done.
Checkstyle ends with 1 errors.Describe what you expect in detail.
UPDATED: OneStatementPerLine should not do any violation on such code .
https://checkstyle.sourceforge.io/checks/coding/emptystatement.html#EmptyStatement should care about empty ; on a line.
Source: checkstyle/checkstyle