Skip to content

Issue #5895: Finish file and audit reports after processing failures - #21520

Merged
romani merged 1 commit into
checkstyle:masterfrom
ishu7w:codex/5895-finish-audit-on-failure
Sep 17, 2026
Merged

romani merged 1 commit into
checkstyle:masterfrom
ishu7w:codex/5895-finish-audit-on-failure

Conversation

@ishu7w

@ishu7w ishu7w commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

Issue: #5895

A processing exception bypasses fileFinished and auditFinished, leaving XML output incomplete or unflushed. This is reproducible on Checkstyle 14.1.0 with a syntax error (class Broken {), a TreeWalker containing MethodLength, and CLI options -f xml -o results.xml: the command fails and leaves a zero-byte report.

Use try-with-resources to finish the audit and each file whose start notification completed. Preserve the original processing failure when completion listeners also throw, attaching cleanup failures as suppressed exceptions. Cached and filtered files do not receive completion notifications. The failing CLI example retains its failure exit code while producing a complete XML report with a file entry.

Add regression tests for XML completion after a check exception and preservation of the original failure when both completion listeners throw. Extend the existing simulated JVM-error/cache test to verify XML completion. Use concrete logger classes for the regressions, and assert that a cached file receives only one completion event. The original XML-completion regression fails before the production change and passes afterward.

Update the Checker Framework baseline for the two private AutoCloseable.close() receiver-type warnings. These completion resources are local to processing and introduce no shared locking state. The branch also includes upstream's PMD integration-test repair; this PR makes no CI-script changes.

The nested-try inspection false positive is tracked in IDEA-393895. The suppression explanation links this issue and documents when it can be removed.

Validation on Java 21:

  • ./mvnw --no-transfer-progress clean verify passed: 6,828 unit tests (two skipped) and 1,367 integration tests, with zero failures or errors.
  • Coverage, source/resource/example checks, PMD, SpotBugs, and report validation passed in that build.
  • Source/resource/example checks passed again after adding the inspection ticket URL.
  • Full verify -Dexec.skip=true passed again after rebasing onto f81aca7, with the same test totals and all verification checks passing. This run reused the previously generated sources.
  • Final commit: bd56220. Fresh CI is running after the rebase; the PR remains a single commit.

Report finalization remains best effort if the process terminates or output/listener implementations fail.

Codex assisted with reproduction, implementation, and validation.

@romani

romani commented Sep 9, 2026

Copy link
Copy Markdown
Member

Please read and watch playlist videos at Starting_Development.
Please make CI green.

@ishu7w
ishu7w force-pushed the codex/5895-finish-audit-on-failure branch from f05bd0e to 0465b61 Compare September 9, 2026 02:41

@arturict arturict left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ran CheckerTest, XMLLoggerTest, MainTest, SarifLoggerTest and DefaultLoggerTest against this head on linux, 226 pass. the try-with-resources instead of a plain finally is what keeps the processing failure as the primary exception when a listener also throws, and testProcessingExceptionPreservedWhenCompletionFails pins exactly that, so the extra interface earns its place.

@romani

romani commented Sep 9, 2026

Copy link
Copy Markdown
Member

Pitest must be resolved by extra test coverage

@romani romani left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Items

import static com.puppycrawl.tools.checkstyle.internal.utils.TestUtil.getExpectedThrowable;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry , no mockito.
Use real classes

@ishu7w ishu7w Sep 10, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed Mockito. The completion-failure regression now uses a concrete DefaultLogger subclass, and the cached-file regression uses the existing counting logger with a fileFinished counter. Rebased onto current master in 07e0ba0. Full local verification passed before the rebase; the rebased local pitest-common run detects all 1,835 mutations with none surviving. All 133 remote checks now pass, including pr-age.

@ishu7w
ishu7w force-pushed the codex/5895-finish-audit-on-failure branch 2 times, most recently from a3fbd98 to 07e0ba0 Compare September 10, 2026 02:53

@romani romani left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

items:


/** Completion notification that preserves processing failures during resource cleanup. */
@FunctionalInterface
private interface AuditCompletion extends AutoCloseable {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

name it FileAuditCompletion as it is file based, not whole Audit.

Comment on lines +219 to +222
fireAuditStarted();
for (final FileSetCheck fsc : fileSetChecks) {
fsc.beginProcessing(charset);
}
final int errorCount;
try (AuditCompletion ignored = this::fireAuditFinished) {
for (final FileSetCheck fsc : fileSetChecks) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this reads in very weird way, even technically it does it job.

please reuse private interface AuditCompletion extends AutoCloseable to make fireAuditStarted when AuditCompletion is started and fireAuditFinished on close.

@ishu7w
ishu7w force-pushed the codex/5895-finish-audit-on-failure branch from 07e0ba0 to 7875c05 Compare September 14, 2026 15:21
@ishu7w

ishu7w commented Sep 14, 2026

Copy link
Copy Markdown
Contributor Author

@romani Addressed both review points in commit 7875c05:

  • The file-scoped helper is FileAuditCompletion; the audit-scoped resource remains AuditCompletion because it owns the whole audit lifecycle.
  • AuditCompletion is now a concrete AutoCloseable. Its constructor sends fireAuditStarted(), and close() sends fireAuditFinished(). Checker.process uses it with try-with-resources so the processing exception remains primary and cleanup exceptions are suppressed.

The focused 226-test suite, Error Prone, lock checker, and source/resource/example checks pass locally.

@ishu7w

ishu7w commented Sep 14, 2026

Copy link
Copy Markdown
Contributor Author

The fresh CircleCI run found one PMD-only issue in the reviewer-requested try-with-resources form: AuditCompletion is intentionally used for its lifecycle side effects, so PMD reported it as an unused local variable.

Commit 566cd88 adds the targeted Checker.process suppression already used by this repository for side-effect-only resources. The exact spotbugs-and-pmd validation now passes locally, along with the focused 226-test suite and the full source/resource/example checks.

@ishu7w
ishu7w force-pushed the codex/5895-finish-audit-on-failure branch from 566cd88 to 7b2b99e Compare September 14, 2026 15:41
@ishu7w

ishu7w commented Sep 14, 2026

Copy link
Copy Markdown
Contributor Author

The git-check-single-commit failure was caused by the two commits on the branch. I squashed the complete change into commit 7b2b99e and force-pushed it with --force-with-lease.

The replacement check now passes: CircleCI git-check-single-commit. The PR currently has one commit and is mergeable.

@romani romani left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Items

@ishu7w
ishu7w force-pushed the codex/5895-finish-audit-on-failure branch from 7b2b99e to 45d3e94 Compare September 14, 2026 16:06
@ishu7w

ishu7w commented Sep 14, 2026

Copy link
Copy Markdown
Contributor Author

@romani Addressed the latest review in 45d3e94: FileAuditCompletion now calls fireFileStarted in its constructor and fireFileFinished in close(). Removed started and start(). The nested try-with-resources begins after cache/filter checks, inside the existing exception-handling block.

Also corrected the squashed commit message that caused CommitValidationTest failures, and documented the two Qodana suppressions for audit notification methods exercised directly through reflection by CheckerTest.

Clean mvn verify passes: 6,818 tests (two skipped), 1,366 integration tests, coverage, PMD, SpotBugs, and source/resource/example checks. The PR remains one commit. Mutation testing and fresh remote CI are running.

@ishu7w
ishu7w force-pushed the codex/5895-finish-audit-on-failure branch 3 times, most recently from da65209 to ce58255 Compare September 14, 2026 17:12

@romani romani left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Items to consider

* @noinspectionreason MethodOnlyUsedFromInnerClass - notification methods are also
* tested directly through reflection in CheckerTest.
*/
private void fireAuditStarted() {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

* deliver filename that was under processing.
* @noinspection NestedTryStatement, ProhibitedExceptionThrown
* @noinspectionreason NestedTryStatement - the inner resource completes file notifications
* before the outer handlers remove failed files from the cache and wrap failures.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ishu7w
ishu7w force-pushed the codex/5895-finish-audit-on-failure branch from ce58255 to 300eb1f Compare September 15, 2026 15:44

@romani romani left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rebase on latest master

* @noinspectionreason ProhibitedExceptionThrown - There is no other way to
* deliver filename that was under processing.
* @noinspection NestedTryStatement, ProhibitedExceptionThrown
* @noinspectionreason NestedTryStatement - the inner try-with-resources has no catch or

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please create issue against idea inspection, to update explain national comment that it is defect in inspection that eventually be fixed

@ishu7w
ishu7w force-pushed the codex/5895-finish-audit-on-failure branch from 300eb1f to 7b70811 Compare September 16, 2026 02:57

@romani romani left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

last:

* deliver filename that was under processing.
* @noinspection NestedTryStatement, ProhibitedExceptionThrown
* @noinspectionreason NestedTryStatement - false positive: the inner try-with-resources
* has no catch or finally to merge. Remove this suppression when the inspection is fixed.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please share ticket number here that you created against inspection

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created IDEA-393895. JetBrains has triaged it under Java. Inspections. Updated the suppression explanation in 13c2ba2 to link the ticket and state that the suppression can be removed when the inspection is fixed.

@ishu7w
ishu7w force-pushed the codex/5895-finish-audit-on-failure branch 2 times, most recently from 13c2ba2 to bd56220 Compare September 16, 2026 14:48
@romani

romani commented Sep 16, 2026

Copy link
Copy Markdown
Member

Qodana Code Quality Brief Issues Report
Rule: JavadocLinkAsPlainText
File: src/main/java/com/puppycrawl/tools/checkstyle/Checker.java
Line: 268
Severity: warning
Message: Link specified as plain text


You can only ticket number, not a url

@ishu7w
ishu7w force-pushed the codex/5895-finish-audit-on-failure branch from bd56220 to 0dc9916 Compare September 16, 2026 16:56
@ishu7w
ishu7w force-pushed the codex/5895-finish-audit-on-failure branch from 0dc9916 to 6cf0da5 Compare September 16, 2026 17:00

@romani romani left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks a lot !!

@romani
romani merged commit 064c119 into checkstyle:master Sep 17, 2026
133 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants