Issue #20330: EmptyLineSeparator false positive on multi-variable field
Fixes #20330
EmptyLineSeparator reported a false positive ',' should be separated from
previous line. on a single multi-variable field declaration such as
int a = 1, b = 2;.
Cause: In a multi-variable declaration the first VARIABLE_DEF's next sibling
is the COMMA, so processVariableDef evaluated
isViolatingEmptyLineBetweenFieldsPolicy(COMMA). That method only treated a
COMMA as non-violating when allowNoEmptyLineBetweenFields=true, so under the
default (false) the comma was flagged — an impossible requirement, since you
cannot put a blank line inside one declaration.
Fix: Treat a COMMA next-sibling as never violating the policy (regardless of
allowNoEmptyLineBetweenFields). The genuine case of two separate adjacent
field declarations (next-sibling is a VARIABLE_DEF) is unchanged and still
governed by allowNoEmptyLineBetweenFields.
Added regression inputs/tests for both the default config (no violation on the
comma, while genuinely unseparated separate fields are still flagged) and
allowNoEmptyLineBetweenFields=true.
./mvnw clean verify passes locally.
Github, generate report for EmptyLineSeparator/all-examples-in-one
Report generation failed. Please check the logs for more details.
Link: https://github.com/checkstyle/checkstyle/actions/runs/27761452172
@mahfouz72 The regression report generation failed during git fetch --tags for https://github.com/pmd/pmd with:
would clobber existing tag
The Maven build part shows BUILD SUCCESS, so this looks like a report-generation/cache issue rather than a failure caused by this PR. Please let me know if you want me to do anything from my side
Can you please try to generate another report with the manual method. I will take a look at the PR asap. Thanks for your contribution.
Can you please try to generate another report with the manual method. I will take a look at the PR asap. Thanks for your contribution.
I tried the manual regression report generation locally as requested.
the report still fails during PMD tag fetching with:
pmd_releases/7.26.0-SNAPSHOT -> pmd_releases/7.26.0-SNAPSHOT (would clobber existing tag)
The Checkstyle build part completes successfully, so this still looks like a regression-report/tooling cache issue rather than a PR code issue.
Please let me know if you want me to try a different report config or if the report should be rerun from CI after the PMD tag issue is handled.
Github, generate report for EmptyLineSeparator/all-examples-in-one
Report for EmptyLineSeparator/all-examples-in-one: https://checkstyle-diff-reports.s3.us-east-2.amazonaws.com/91dae1e27e2ec85bc212abe276c091f76d84dd4c_2026033610/reports/diff/index.html
@romani I rebased the PR on the latest upstream/master to reduce report noise
Github, generate report for EmptyLineSeparator/all-examples-in-one
I rebased the PR on the latest upstream/master to reduce report noise
These are not noise changes. I believe all of them are valid diffs. We removed all violations related to multi-variable declarations separated by commas, which resulted in a large number of changes.
@romani good to go