checkstyle icon indicating copy to clipboard operation
checkstyle copied to clipboard

Issue #20330: EmptyLineSeparator false positive on multi-variable field

Open surajgojanur opened this issue 5 months ago • 10 comments

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.

surajgojanur avatar Jun 15 '26 04:06 surajgojanur

Github, generate report for EmptyLineSeparator/all-examples-in-one

mahfouz72 avatar Jun 18 '26 13:06 mahfouz72

Report generation failed. Please check the logs for more details.
Link: https://github.com/checkstyle/checkstyle/actions/runs/27761452172

github-actions[bot] avatar Jun 18 '26 13:06 github-actions[bot]

@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

surajgojanur avatar Jun 19 '26 13:06 surajgojanur

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.

mahfouz72 avatar Jun 19 '26 13:06 mahfouz72

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.

surajgojanur avatar Jun 19 '26 19:06 surajgojanur

Github, generate report for EmptyLineSeparator/all-examples-in-one

romani avatar Jun 20 '26 02:06 romani

Report for EmptyLineSeparator/all-examples-in-one: https://checkstyle-diff-reports.s3.us-east-2.amazonaws.com/91dae1e27e2ec85bc212abe276c091f76d84dd4c_2026033610/reports/diff/index.html

github-actions[bot] avatar Jun 20 '26 03:06 github-actions[bot]

@romani I rebased the PR on the latest upstream/master to reduce report noise

surajgojanur avatar Jun 20 '26 08:06 surajgojanur

Github, generate report for EmptyLineSeparator/all-examples-in-one

surajgojanur avatar Jun 20 '26 08:06 surajgojanur

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.

mahfouz72 avatar Jun 21 '26 22:06 mahfouz72

@romani good to go

surajgojanur avatar Jun 28 '26 13:06 surajgojanur