[ 
https://issues.apache.org/jira/browse/GROOVY-12708?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18139326#comment-18139326
 ] 

ASF GitHub Bot commented on GROOVY-12708:
-----------------------------------------

codecov-commenter commented on PR #3238:
URL: https://github.com/apache/groovy/pull/3238#issuecomment-6675240012

   ## 
[Codecov](https://app.codecov.io/gh/apache/groovy/pull/3238?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
 Report
   :x: Patch coverage is `70.96774%` with `9 lines` in your changes missing 
coverage. Please review.
   :white_check_mark: Project coverage is 74.1797%. 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 
([`0bae8b3`](https://app.codecov.io/gh/apache/groovy/commit/0bae8b37ea3df2091144361dc9d723a928885105?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
   
   | [Files with missing 
lines](https://app.codecov.io/gh/apache/groovy/pull/3238?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
 | Patch % | Lines |
   |---|---|---|
   | 
[...ain/groovy/groovy/typecheckers/RegexChecker.groovy](https://app.codecov.io/gh/apache/groovy/pull/3238?src=pr&el=tree&filepath=subprojects%2Fgroovy-typecheckers%2Fsrc%2Fmain%2Fgroovy%2Fgroovy%2Ftypecheckers%2FRegexChecker.groovy&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3VicHJvamVjdHMvZ3Jvb3Z5LXR5cGVjaGVja2Vycy9zcmMvbWFpbi9ncm9vdnkvZ3Jvb3Z5L3R5cGVjaGVja2Vycy9SZWdleENoZWNrZXIuZ3Jvb3Z5)
 | 70.9677% | [1 Missing and 8 partials :warning: 
](https://app.codecov.io/gh/apache/groovy/pull/3238?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
 |
   
   <details><summary>Additional details and impacted files</summary>
   
   
   
   [![Impacted file tree 
graph](https://app.codecov.io/gh/apache/groovy/pull/3238/graphs/tree.svg?width=650&height=150&src=pr&token=1r45138NfQ&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)](https://app.codecov.io/gh/apache/groovy/pull/3238?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
   
   ```diff
   @@                Coverage Diff                 @@
   ##               master      #3238        +/-   ##
   ==================================================
   + Coverage     74.1763%   74.1797%   +0.0033%     
   - Complexity      43806      43811         +5     
   ==================================================
     Files            1692       1692                
     Lines          149758     149785        +27     
     Branches        28417      28430        +13     
   ==================================================
   + Hits           111085     111110        +25     
   + Misses          28465      28462         -3     
   - Partials        10208      10213         +5     
   ```
   
   | [Files with missing 
lines](https://app.codecov.io/gh/apache/groovy/pull/3238?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
 | Coverage Δ | |
   |---|---|---|
   | 
[...ain/groovy/groovy/typecheckers/RegexChecker.groovy](https://app.codecov.io/gh/apache/groovy/pull/3238?src=pr&el=tree&filepath=subprojects%2Fgroovy-typecheckers%2Fsrc%2Fmain%2Fgroovy%2Fgroovy%2Ftypecheckers%2FRegexChecker.groovy&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3VicHJvamVjdHMvZ3Jvb3Z5LXR5cGVjaGVja2Vycy9zcmMvbWFpbi9ncm9vdnkvZ3Jvb3Z5L3R5cGVjaGVja2Vycy9SZWdleENoZWNrZXIuZ3Jvb3Z5)
 | `78.9773% <70.9677%> (-2.2308%)` | :arrow_down: |
   
   ... and [13 files with indirect coverage 
changes](https://app.codecov.io/gh/apache/groovy/pull/3238/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>




> RegexChecker ignores the flags argument of Pattern.compile
> ----------------------------------------------------------
>
>                 Key: GROOVY-12708
>                 URL: https://issues.apache.org/jira/browse/GROOVY-12708
>             Project: Groovy
>          Issue Type: Bug
>    Affects Versions: 5.1.3, 6.0.0
>            Reporter: Paul King
>            Priority: Major
>
> h2. Problem
> {{groovy.typecheckers.RegexChecker}} checks {{Pattern.compile(regex, flags)}} 
> by compiling {{regex}} without {{flags}}. Most flags don't affect whether a 
> regex is valid or how many groups it has, but {{Pattern.COMMENTS}} and 
> {{Pattern.LITERAL}} change how the regex text is parsed, so the checker 
> checks a different regex from the one that runs:
> * *Valid code is rejected* with "Bad regex", when the regex is only valid 
> with the flag.
> * *Errors are missed*, when the group count without the flag is higher than 
> the real one (text in a COMMENTS-mode comment, or a LITERAL regex, which has 
> no groups).
> Reproducer, run with {{groovy --configscript config.groovy comments.groovy}}:
> {code:groovy|title=config.groovy}
> import groovy.transform.TypeChecked
> withConfig(configuration) {
>     ast(TypeChecked, extensions: 'groovy.typecheckers.RegexChecker')
> }
> {code}
> {code:groovy|title=comments.groovy}
> import java.util.regex.Pattern
> assert Pattern.compile('(a) # (b', Pattern.COMMENTS).matcher('a').matches()
> {code}
> Actual:
> {noformat}
> [Static type checking] - Bad regex: Unclosed group near index 8
> {noformat}
> Expected: the script compiles and the assertion passes, as it does without 
> the extension.
> ||Script||Actual (4.0.32, 5.1.3, 6.0.0)||Expected||
> |{{Pattern.compile('(a) # (b', Pattern.COMMENTS)}}|"Bad regex: Unclosed group 
> near index 8"|compiles|
> |{{Pattern.compile('(?< first >a)', Pattern.COMMENTS)}}|"Bad regex: capturing 
> group name does not start with a Latin letter near index 3"|compiles|
> |{{Pattern.compile('a(b', Pattern.LITERAL)}}|"Bad regex: Unclosed group near 
> index 3"|compiles|
> |{{Matcher m = Pattern.compile('(a) # (b)', Pattern.COMMENTS).matcher('a')}}, 
> then {{m.group(2)}}|compiles, then {{IndexOutOfBoundsException: No group 2}} 
> at runtime (6.0.0)|"Invalid group count 2 for regex with 1 group"|
> |{{Matcher m = Pattern.compile('(a)', Pattern.LITERAL).matcher('(a)')}}, then 
> {{m.group(1)}}|compiles, then {{IndexOutOfBoundsException: No group 1}} at 
> runtime (6.0.0)|"Invalid group count 1 for regex with 0 groups"|
> The same flags written inline, such as {{(?x)}}, are handled correctly, 
> because the JDK applies them when the checker compiles the regex.
> On 4.0.32 and 5.1.3 the last two scripts instead fail with an unrelated 
> general error in {{findTargetVariable}}, from a crash on 
> {{Pattern.compile(...).matcher(...)}} that was fixed before 6.0.0.
> h2. Proposed fix
> Work out the flags argument at compile time and compile the regex with it. 
> Then "Bad regex", the group count, the named-group check and the 
> {{matcher[...][...]}} type inference all apply to the regex that actually 
> runs. The flags can be written as:
> * an {{int}} constant;
> * a {{Pattern}} constant such as {{Pattern.COMMENTS}}, read from the 
> {{Pattern}} class by name;
> * constants combined with {{|}};
> * a local variable or field holding one of these, as already allowed for the 
> regex string.
> When the flags can't be worked out (a parameter, a method call), skip the 
> checks for that call and record no group count, because the result depends on 
> flags that are only known at runtime.
> A LITERAL regex has no groups at all. The named-group check (GROOVY-12707) 
> works by compiling the regex with a named backreference added to the end, but 
> under LITERAL that text is literal, so every name would look defined. Record 
> a LITERAL regex as having no named groups instead.
> h2. Tests
> * Each row of the table above.
> * Flags written as {{Pattern.COMMENTS}}, {{Pattern.COMMENTS | 
> Pattern.CASE_INSENSITIVE}}, an {{int}} constant and a local variable, with 
> the same results.
> * Flags that can't be worked out (a method parameter): no "Bad regex" error 
> and no group-count error.
> * A named group under COMMENTS passed as a flag ({{Pattern.compile('(?< first 
> >a)', Pattern.COMMENTS)}}, then {{m.group('first')}}) compiles, and an 
> undefined name is reported.
> * Flags that don't change parsing ({{CASE_INSENSITIVE}}) give the same 
> results as no flags.



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to