[
https://issues.apache.org/jira/browse/GROOVY-12709?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18139330#comment-18139330
]
ASF GitHub Bot commented on GROOVY-12709:
-----------------------------------------
codecov-commenter commented on PR #3239:
URL: https://github.com/apache/groovy/pull/3239#issuecomment-6675307404
##
[Codecov](https://app.codecov.io/gh/apache/groovy/pull/3239?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
Report
:white_check_mark: All modified and coverable lines are covered by tests.
:white_check_mark: Project coverage is 74.1795%. Comparing base
([`04b8160`](https://app.codecov.io/gh/apache/groovy/commit/04b8160fd112dc086d0785e25ae2f4e6925ec359?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache))
to head
([`470468b`](https://app.codecov.io/gh/apache/groovy/commit/470468b955dd809f5971841548710b72126d551e?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
<details><summary>Additional details and impacted files</summary>
[](https://app.codecov.io/gh/apache/groovy/pull/3239?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
```diff
@@ Coverage Diff @@
## master #3239 +/- ##
==================================================
+ Coverage 74.1763% 74.1795% +0.0032%
- Complexity 43806 43809 +3
==================================================
Files 1692 1692
Lines 149758 149761 +3
Branches 28417 28418 +1
==================================================
+ Hits 111085 111092 +7
- Misses 28465 28466 +1
+ Partials 10208 10203 -5
```
| [Files with missing
lines](https://app.codecov.io/gh/apache/groovy/pull/3239?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
| Coverage Δ | |
|---|---|---|
|
[.../apache/groovy/typecheckers/CheckingVisitor.groovy](https://app.codecov.io/gh/apache/groovy/pull/3239?src=pr&el=tree&filepath=subprojects%2Fgroovy-typecheckers%2Fsrc%2Fmain%2Fgroovy%2Forg%2Fapache%2Fgroovy%2Ftypecheckers%2FCheckingVisitor.groovy&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3VicHJvamVjdHMvZ3Jvb3Z5LXR5cGVjaGVja2Vycy9zcmMvbWFpbi9ncm9vdnkvb3JnL2FwYWNoZS9ncm9vdnkvdHlwZWNoZWNrZXJzL0NoZWNraW5nVmlzaXRvci5ncm9vdnk=)
| `89.4737% <100.0000%> (+1.9737%)` | :arrow_up: |
... and [9 files with indirect coverage
changes](https://app.codecov.io/gh/apache/groovy/pull/3239/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
</details>
<details><summary> :rocket: New features to boost your workflow: </summary>
- :snowflake: [Test
Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests,
report on failures, and find test suite problems.
- :package: [JS Bundle
Analysis](https://docs.codecov.com/docs/javascript-bundle-analysis): Save
yourself from yourself by tracking and limiting bundle sizes in JS merges.
</details>
> Type checkers overflow the stack on fields whose initializers refer to each
> other
> ---------------------------------------------------------------------------------
>
> Key: GROOVY-12709
> URL: https://issues.apache.org/jira/browse/GROOVY-12709
> Project: Groovy
> Issue Type: Bug
> Affects Versions: 5.1.3, 6.0.0
> Reporter: Paul King
> Priority: Major
>
> h2. Problem
> With {{groovy.typecheckers.RegexChecker}} or
> {{groovy.typecheckers.FormatStringChecker}} enabled, compiling code that uses
> a field whose initializer refers, directly or through other fields, back to
> itself makes the compiler throw {{java.lang.StackOverflowError}}. The error
> isn't turned into a compilation error, so the compile is aborted.
> Reproducer, run with {{groovy --configscript config.groovy cycle.groovy}}:
> {code:groovy|title=config.groovy}
> import groovy.transform.TypeChecked
> withConfig(configuration) {
> ast(TypeChecked, extensions: 'groovy.typecheckers.RegexChecker')
> }
> {code}
> {code:groovy|title=cycle.groovy}
> import java.util.regex.Pattern
> class Cycle {
> static String R = S
> static String S = R
> static Pattern compile() { Pattern.compile(R) }
> }
> println 'compiled ' + Cycle.R
> {code}
> Actual:
> {noformat}
> java.lang.StackOverflowError
> ...
> at
> org.apache.groovy.typecheckers.CheckingVisitor.findTargetVariable(CheckingVisitor.groovy)
> at
> org.apache.groovy.typecheckers.CheckingVisitor.findConstExp(CheckingVisitor.groovy)
> at
> org.apache.groovy.typecheckers.CheckingVisitor.findConstExp(CheckingVisitor.groovy)
> ...
> {noformat}
> Expected: the script compiles and prints {{compiled null}}, as it does
> without the extension. The fields have no constant value to find, so there is
> nothing to check.
> The same happens with {{FormatStringChecker}}, for example {{String.format(F,
> 1)}} with {{static String F = G}} and {{static String G = F}}, and with
> {{final}} instance fields ({{final String a = b}}, {{final String b = a}}).
> ||Version||RegexChecker||FormatStringChecker||
> |4.0.32|StackOverflowError|(checker not available)|
> |5.1.3|StackOverflowError|StackOverflowError|
> |6.0.0|StackOverflowError|StackOverflowError|
> The same cycle of {{static final}} fields overflows the compiler even without
> these checkers; that is GROOVY-12710.
> h2. Cause
> {{CheckingVisitor.findConstExp}} finds the constant value of an expression.
> For a variable that resolves to a field with an initializer, whether or not
> the field is {{final}}, it calls itself on that initializer. Nothing records
> which fields it has already followed, so a chain of initializers that leads
> back to an earlier field recurses until the stack overflows.
> {{findConstExp}} is shared by RegexChecker and FormatStringChecker; the other
> checkers in groovy-typecheckers don't call it.
> h2. Proposed fix
> Track the variables already followed during one lookup, and return {{null}}
> (no constant value) when a variable is reached a second time. This matches
> how {{findConstExp}} already treats any other value it can't determine.
> h2. Tests
> * The reproducer above, for both RegexChecker and FormatStringChecker:
> compiles, and runs.
> * A longer cycle, of {{final}} instance fields ({{a = b}}, {{b = c}}, {{c =
> a}}).
> * A chain of fields that ends in a constant ({{static final String R = S}},
> {{static final String S = /(a)/}}) is still followed and checked; for
> example, a bad group number is still reported.
> * {{static final}} cycles are left out until GROOVY-12710 is fixed.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)