Skip to content

GROOVY-12306: Error tolerance is not applied to type checking errors and has no unlimited setting - #2835

Open
paulk-asert wants to merge 5 commits into
apache:masterfrom
paulk-asert:groovy12306
Open

GROOVY-12306: Error tolerance is not applied to type checking errors and has no unlimited setting#2835
paulk-asert wants to merge 5 commits into
apache:masterfrom
paulk-asert:groovy12306

Conversation

@paulk-asert

Copy link
Copy Markdown
Contributor

No description provided.

The configured error tolerance was only enforced for errors reported through
SourceUnit#addError. Errors reported through ClassCodeVisitorSupport#addError
went straight to ErrorCollector#addErrorAndContinue and so were unbounded,
which meant `groovyc -t 1` had no effect on the most common error class in
@CompileStatic code: type checking errors reported in full however low the
tolerance was set.

Route the base ClassCodeVisitorSupport#addError through the tolerance-aware
ErrorCollector#addError. StaticTypeCheckingVisitor overrides addError for
its own error de-duplication and needs the same treatment, but only for the
source unit's own collector: the temporary collectors it pushes for
speculative checks must continue to collect without bailing out, since their
errors are routinely discarded once a candidate is ruled in or out.

ClassCompletionVerifierTest counts every error the verifier reports, so it
now asks for the unlimited tolerance it always relied on rather than the
fail-fast tolerance of 1 that SourceUnit#create(String,String) selects.

Assisted-by: Claude Opus 5 (1M context) via Claude Code
There was no way to ask the compiler to report every error. `groovyc -t 0`
was silently discarded, because CompilationOptions could not tell a supplied
zero from the option being absent, leaving the default of 10 in place; and
even when set, a tolerance of zero would have bailed out on the first error
rather than collecting them all.

Treat a tolerance of zero or less as unlimited in ErrorCollector, and hold
the command-line option in a boxed Integer so that an explicit zero reaches
the configuration. Name the default as CompilerConfiguration.DEFAULT_TOLERANCE
rather than repeating the literal, and state it in the option help, which
previously gave no hint that the option was bounded by default.

The option itself has been undocumented since it was added in GROOVY-11194,
so add it to the groovyc option table too.

Assisted-by: Claude Opus 5 (1M context) via Claude Code
The error tolerance could be set on the groovyc command line and through the
CompilerConfiguration API, but the <groovyc> Ant task offered no way to reach
it short of a compiler configuration script.

Add a tolerance attribute. Both the forked and in-process paths run the same
assembled argument list through the FileSystemCompiler parser, so emitting
the option once covers both. An unset attribute emits nothing and leaves the
compiler default in place, while an explicit zero is passed through as the
request for unlimited error reporting that it is.

Assisted-by: Claude Opus 5 (1M context) via Claude Code
@paulk-asert paulk-asert changed the title Groovy12306 GROOVY-12306: Error tolerance is not applied to type checking errors and has no unlimited setting Aug 27, 2026
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 86.36364% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 70.6608%. Comparing base (914da78) to head (109fa29).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
...va/org/codehaus/groovy/control/ErrorCollector.java 50.0000% 0 Missing and 1 partial ⚠️
...n/java/org/codehaus/groovy/control/SourceUnit.java 0.0000% 1 Missing ⚠️
...src/main/java/org/codehaus/groovy/ant/Groovyc.java 83.3333% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@                Coverage Diff                 @@
##               master      #2835        +/-   ##
==================================================
+ Coverage     70.6486%   70.6608%   +0.0122%     
- Complexity      36522      36539        +17     
==================================================
  Files            1571       1571                
  Lines          133963     133981        +18     
  Branches        24690      24692         +2     
==================================================
+ Hits            94643      94672        +29     
+ Misses          30802      30795         -7     
+ Partials         8518       8514         -4     
Files with missing lines Coverage Δ
...g/codehaus/groovy/ast/ClassCodeVisitorSupport.java 100.0000% <100.0000%> (ø)
...codehaus/groovy/control/CompilerConfiguration.java 75.1534% <100.0000%> (ø)
.../org/codehaus/groovy/tools/FileSystemCompiler.java 54.7619% <100.0000%> (+0.9524%) ⬆️
...roovy/transform/stc/StaticTypeCheckingVisitor.java 87.2758% <100.0000%> (+0.0156%) ⬆️
...va/org/codehaus/groovy/control/ErrorCollector.java 63.5417% <50.0000%> (+0.3838%) ⬆️
...n/java/org/codehaus/groovy/control/SourceUnit.java 71.9512% <0.0000%> (+5.2846%) ⬆️
...src/main/java/org/codehaus/groovy/ant/Groovyc.java 52.7132% <83.3333%> (+0.7524%) ⬆️

... and 8 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@testlens-app

testlens-app Bot commented Aug 27, 2026

Copy link
Copy Markdown

✅ All tests passed ✅

🏷️ Commit: 109fa29
▶️ Tests: 113332 executed
⚪️ Checks: 31/31 completed


Learn more about TestLens at testlens.app/docs.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Extends compiler error tolerance to static type-checking and visitor errors, adds unlimited reporting, and exposes tolerance through compiler front ends.

Changes:

  • Enforces tolerance consistently and treats non-positive values as unlimited.
  • Adds CLI and Ant task support.
  • Adds regression tests and documentation.

Reviewed changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
COMPATIBILITY.md Documents compatibility impact.
src/main/java/org/codehaus/groovy/ast/ClassCodeVisitorSupport.java Applies tolerance to visitor errors.
src/main/java/org/codehaus/groovy/control/CompilerConfiguration.java Defines default and unlimited semantics.
src/main/java/org/codehaus/groovy/control/ErrorCollector.java Implements unlimited tolerance.
src/main/java/org/codehaus/groovy/control/SourceUnit.java Clarifies legacy and factory behavior.
src/main/java/org/codehaus/groovy/tools/FileSystemCompiler.java Preserves explicit zero from CLI parsing.
src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java Enforces tolerance for type-checking errors.
src/spec/doc/tools-groovyc.adoc Documents the CLI option.
src/test/groovy/org/codehaus/groovy/classgen/ClassCompletionVerifierTest.java Requests unlimited errors in verifier tests.
src/test/groovy/org/codehaus/groovy/control/ErrorToleranceTest.groovy Tests tolerance across error paths.
src/test/groovy/org/codehaus/groovy/tools/FileSystemCompilerTest.java Tests CLI tolerance parsing.
subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/Groovyc.java Adds the Ant task attribute.
subprojects/groovy-ant/src/spec/doc/groovyc-ant-task.adoc Documents the Ant attribute.
subprojects/groovy-ant/src/test/groovy/org/codehaus/groovy/ant/GroovycToleranceTest.java Tests Ant argument propagation.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread COMPATIBILITY.md
Comment on lines +373 to +379
The compiler's error tolerance — the number of non-fatal errors collected
before compilation is abandoned, `CompilerConfiguration.getTolerance()`,
`groovyc -t` — is now enforced for every error kind. It previously covered
only errors reported through `SourceUnit#addError` (parse and class
generation); errors reported through `ClassCodeVisitorSupport#addError`,
which includes all static type checking errors, went straight to
`ErrorCollector#addErrorAndContinue` and were unbounded.
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