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

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

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

   ## 
[Codecov](https://app.codecov.io/gh/apache/groovy/pull/3207?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.1500%. Comparing base 
([`9a1a0d0`](https://app.codecov.io/gh/apache/groovy/commit/9a1a0d0ccbc9a1eacd85cbbd408374f6c7f41fc8?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache))
 to head 
([`50f9294`](https://app.codecov.io/gh/apache/groovy/commit/50f9294729df3ced92c836e3775655f1e190995a?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
   :warning: Report is 3 commits behind head on master.
   
   <details><summary>Additional details and impacted files</summary>
   
   
   
   [![Impacted file tree 
graph](https://app.codecov.io/gh/apache/groovy/pull/3207/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/3207?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
   
   ```diff
   @@                Coverage Diff                 @@
   ##               master      #3207        +/-   ##
   ==================================================
   - Coverage     74.1518%   74.1500%   -0.0018%     
   + Complexity      43728      43726         -2     
   ==================================================
     Files            1692       1692                
     Lines          149527     149528         +1     
     Branches        28360      28364         +4     
   ==================================================
   - Hits           110877     110875         -2     
   - Misses          28438      28443         +5     
   + Partials        10212      10210         -2     
   ```
   
   | [Files with missing 
lines](https://app.codecov.io/gh/apache/groovy/pull/3207?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
 | Coverage Δ | |
   |---|---|---|
   | 
[...ovy/groovy/typecheckers/FormatStringChecker.groovy](https://app.codecov.io/gh/apache/groovy/pull/3207?src=pr&el=tree&filepath=subprojects%2Fgroovy-typecheckers%2Fsrc%2Fmain%2Fgroovy%2Fgroovy%2Ftypecheckers%2FFormatStringChecker.groovy&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3VicHJvamVjdHMvZ3Jvb3Z5LXR5cGVjaGVja2Vycy9zcmMvbWFpbi9ncm9vdnkvZ3Jvb3Z5L3R5cGVjaGVja2Vycy9Gb3JtYXRTdHJpbmdDaGVja2VyLmdyb292eQ==)
 | `78.2609% <100.0000%> (+0.1587%)` | :arrow_up: |
   | 
[...ain/groovy/groovy/typecheckers/RegexChecker.groovy](https://app.codecov.io/gh/apache/groovy/pull/3207?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)
 | `74.6377% <100.0000%> (ø)` | |
   
   ... and [13 files with indirect coverage 
changes](https://app.codecov.io/gh/apache/groovy/pull/3207/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>




> FormatStringChecker fails inside the compiler on enum and record declarations
> -----------------------------------------------------------------------------
>
>                 Key: GROOVY-12688
>                 URL: https://issues.apache.org/jira/browse/GROOVY-12688
>             Project: Groovy
>          Issue Type: Bug
>    Affects Versions: 6.0.0
>            Reporter: Scott Murphy Heiberg
>            Priority: Major
>
> With {{groovy.typecheckers.FormatStringChecker}} enabled, a class that 
> declares an enum or a record does not compile: the checker throws a 
> {{NullPointerException}} on a constructor call the compiler generated, and 
> the compiler reports a general error. The source contains no format call.
> {{Size.groovy}} and {{Point.groovy}}:
> {code:groovy}
> import groovy.transform.TypeChecked
> @TypeChecked(extensions = 'groovy.typecheckers.FormatStringChecker')
> enum Size { S, M }
> {code}
> {code:groovy}
> import groovy.transform.TypeChecked
> @TypeChecked(extensions = 'groovy.typecheckers.FormatStringChecker')
> record Point(int x, int y) {}
> {code}
> {code:sh}
> groovyc --check --error-format=short Size.groovy
> groovyc --check --error-format=short Point.groovy
> {code}
> Actual, for each: exit 1 and
> {code:text}
> org.codehaus.groovy.control.MultipleCompilationErrorsException: startup 
> failed:
> error: General error during canonicalization: Cannot get property 
> 'annotations' on null object
> 1 error
> {code}
> With {{groovyc -e --check Size.groovy}}:
> {code:text}
> java.lang.NullPointerException: Cannot get property 'annotations' on null 
> object
>       at 
> org.codehaus.groovy.runtime.NullObject.getProperty(NullObject.java:99)
>       at 
> groovy.typecheckers.FormatStringChecker$_run_closure8.doCall(FormatStringChecker.groovy:100)
>       at groovy.lang.Closure.invokeHandle(Closure.java:647)
>       at groovy.lang.Closure.invokeCached(Closure.java:618)
>       at groovy.lang.Closure.call(Closure.java:584)
>       at 
> org.codehaus.groovy.transform.stc.AbstractTypeCheckingExtension.safeCall(AbstractTypeCheckingExtension.java:253)
>       at 
> org.codehaus.groovy.transform.stc.GroovyTypeCheckingExtensionSupport.afterMethodCall(GroovyTypeCheckingExtensionSupport.java:364)
>       at 
> org.codehaus.groovy.transform.stc.DefaultTypeCheckingExtension.afterMethodCall(DefaultTypeCheckingExtension.java:192)
>       at 
> org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.visitConstructorCallExpression(StaticTypeCheckingVisitor.java:3288)
>       at 
> org.codehaus.groovy.ast.expr.ConstructorCallExpression.visit(ConstructorCallExpression.java:74)
>       at 
> org.codehaus.groovy.ast.CodeVisitorSupport.visitReturnStatement(CodeVisitorSupport.java:181)
>       ...
> {code}
> Expected: both compile, as {{@TypeChecked enum PlainEnum { S, M }}} does 
> (exit 0). The same failure appears under static compilation applied by a 
> config script ({{ast(groovy.transform.CompileStatic, extensions: 
> ['groovy.typecheckers.FormatStringChecker'])}}) to a script containing {{enum 
> Size { S, M }}} and {{println Size.M}}, and when the enum or record is nested 
> in a checked class. 6.0.0-beta-1, 5.0.8 and 5.0.0 fail the same way, and so 
> does current master; this is not a late regression.
> Cause: when the type checker cannot resolve a constructor call in generated 
> code (an enum's synthetic {{$INIT}} delegation, or a record's named-argument 
> constructor delegation) it drops the error silently and stores no target 
> method, but still fires {{afterMethodCall}}, where FormatStringChecker reads 
> {{annotations}} from that null target (line 100). Methods without a body 
> (abstract or interface methods, or an enum with constant bodies) crash a 
> second way, {{method.code.visit}} on a null {{code}}, which also affects 
> RegexChecker. The other checkers in the module guard their target lookups and 
> are not affected.
> A fix that works: return early from {{afterMethodCall}} when the target 
> method is null, and visit {{method.code}} only when it exists, in 
> FormatStringChecker and RegexChecker. With it, enums, records, nested 
> declarations and body-less methods compile cleanly under both checkers, and a 
> genuine format-string mismatch in such a class is still reported. A pull 
> request with regression tests in {{FormatStringCheckerTest}} and 
> {{RegexCheckerTest}} follows.
> Impact: FormatStringChecker was graduated to stable for 6.0.0 (GROOVY-12039). 
> Any checked class that declares an enum or record cannot be compiled with it. 
> Workaround: leave FormatStringChecker off for such sources.
> Environment: Groovy 6.0.0 on BellSoft JDK 21.0.12, macOS 26.5 (arm64); 
> reproduced on master at 9a1a0d0ccb with JDK 21.



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

Reply via email to