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

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

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

   ## 
[Codecov](https://app.codecov.io/gh/apache/groovy/pull/3275?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 `90.47619%` with `2 lines` in your changes missing 
coverage. Please review.
   :white_check_mark: Project coverage is 74.4220%. Comparing base 
([`df1fe66`](https://app.codecov.io/gh/apache/groovy/commit/df1fe66ed134c0ec484117a526e2e8a420307e0b?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache))
 to head 
([`f6d46b4`](https://app.codecov.io/gh/apache/groovy/commit/f6d46b458b8301bb0d001512cc365c29d345769c?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
   :warning: Report is 2 commits behind head on master.
   
   | [Files with missing 
lines](https://app.codecov.io/gh/apache/groovy/pull/3275?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
 | Patch % | Lines |
   |---|---|---|
   | 
[...ontracts/ast/visitor/AnnotationClosureVisitor.java](https://app.codecov.io/gh/apache/groovy/pull/3275?src=pr&el=tree&filepath=subprojects%2Fgroovy-contracts%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fgroovy%2Fcontracts%2Fast%2Fvisitor%2FAnnotationClosureVisitor.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3VicHJvamVjdHMvZ3Jvb3Z5LWNvbnRyYWN0cy9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvZ3Jvb3Z5L2NvbnRyYWN0cy9hc3QvdmlzaXRvci9Bbm5vdGF0aW9uQ2xvc3VyZVZpc2l0b3IuamF2YQ==)
 | 88.8889% | [0 Missing and 1 partial :warning: 
](https://app.codecov.io/gh/apache/groovy/pull/3275?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
 |
   | 
[.../apache/groovy/contracts/util/ExpressionUtils.java](https://app.codecov.io/gh/apache/groovy/pull/3275?src=pr&el=tree&filepath=subprojects%2Fgroovy-contracts%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fgroovy%2Fcontracts%2Futil%2FExpressionUtils.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3VicHJvamVjdHMvZ3Jvb3Z5LWNvbnRyYWN0cy9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvZ3Jvb3Z5L2NvbnRyYWN0cy91dGlsL0V4cHJlc3Npb25VdGlscy5qYXZh)
 | 66.6667% | [0 Missing and 1 partial :warning: 
](https://app.codecov.io/gh/apache/groovy/pull/3275?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/3275/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/3275?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
   
   ```diff
   @@                Coverage Diff                 @@
   ##               master      #3275        +/-   ##
   ==================================================
   + Coverage     74.4140%   74.4220%   +0.0080%     
   - Complexity      44379      44408        +29     
   ==================================================
     Files            1699       1699                
     Lines          151067     151169       +102     
     Branches        28790      28806        +16     
   ==================================================
   + Hits           112415     112503        +88     
   - Misses          28380      28388         +8     
   - Partials        10272      10278         +6     
   ```
   
   | [Files with missing 
lines](https://app.codecov.io/gh/apache/groovy/pull/3275?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
 | Coverage Δ | |
   |---|---|---|
   | 
[.../contracts/ast/LoopInvariantASTTransformation.java](https://app.codecov.io/gh/apache/groovy/pull/3275?src=pr&el=tree&filepath=subprojects%2Fgroovy-contracts%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fgroovy%2Fcontracts%2Fast%2FLoopInvariantASTTransformation.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3VicHJvamVjdHMvZ3Jvb3Z5LWNvbnRyYWN0cy9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvZ3Jvb3Z5L2NvbnRyYWN0cy9hc3QvTG9vcEludmFyaWFudEFTVFRyYW5zZm9ybWF0aW9uLmphdmE=)
 | `69.3878% <100.0000%> (+6.8878%)` | :arrow_up: |
   | 
[...ontracts/ast/visitor/AnnotationClosureVisitor.java](https://app.codecov.io/gh/apache/groovy/pull/3275?src=pr&el=tree&filepath=subprojects%2Fgroovy-contracts%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fgroovy%2Fcontracts%2Fast%2Fvisitor%2FAnnotationClosureVisitor.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3VicHJvamVjdHMvZ3Jvb3Z5LWNvbnRyYWN0cy9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvZ3Jvb3Z5L2NvbnRyYWN0cy9hc3QvdmlzaXRvci9Bbm5vdGF0aW9uQ2xvc3VyZVZpc2l0b3IuamF2YQ==)
 | `91.5698% <88.8889%> (+0.7686%)` | :arrow_up: |
   | 
[.../apache/groovy/contracts/util/ExpressionUtils.java](https://app.codecov.io/gh/apache/groovy/pull/3275?src=pr&el=tree&filepath=subprojects%2Fgroovy-contracts%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fgroovy%2Fcontracts%2Futil%2FExpressionUtils.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3VicHJvamVjdHMvZ3Jvb3Z5LWNvbnRyYWN0cy9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvZ3Jvb3Z5L2NvbnRyYWN0cy91dGlsL0V4cHJlc3Npb25VdGlscy5qYXZh)
 | `85.1064% <66.6667%> (+3.2882%)` | :arrow_up: |
   
   ... and [22 files with indirect coverage 
changes](https://app.codecov.io/gh/apache/groovy/pull/3275/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>




> groovy-contracts: a contract closure holding a return, assert or if 
> statement, or declaring an empty parameter list, crashes the compiler with a 
> NullPointerException
> ---------------------------------------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: GROOVY-12740
>                 URL: https://issues.apache.org/jira/browse/GROOVY-12740
>             Project: Groovy
>          Issue Type: Bug
>          Components: groovy-contracts
>    Affects Versions: 6.0.0
>            Reporter: Scott Murphy Heiberg
>            Priority: Major
>
> A {{@Requires}}, {{@Ensures}} or {{@Invariant}} closure whose body is not a 
> plain expression crashes the compiler with an internal error instead of a 
> compile error. A closure that declares an empty parameter list with an 
> explicit arrow, which is a valid closure, crashes it too.
> {code:groovy}
> import groovy.contracts.*
> class Account {
>     @Requires({ return amount > 0 })  // 1
>     // @Requires({ assert amount > 0 })  // 2
>     // @Requires({ if (amount <= 0) throw new 
> IllegalArgumentException('amount') }) // 3
>     // @Requires({ -> amount > 0 })  // 4
>     void deposit(BigDecimal amount) {}
> }
> {code}
> Forms 1 to 3 fail with:
> {noformat}
> BUG! exception in phase 'semantic analysis' in source unit 'Account.groovy' 
> Cannot invoke 
> "org.codehaus.groovy.ast.expr.BooleanExpression.getNodeMetaData(Object)" 
> because "booleanExpression" is null
>       at 
> org.apache.groovy.contracts.generation.AssertStatementCreationUtility.getAssertionStatement(AssertStatementCreationUtility.java:85)
>       at 
> org.apache.groovy.contracts.generation.AssertStatementCreationUtility.getAssertionStatements(AssertStatementCreationUtility.java:67)
>       at 
> org.apache.groovy.contracts.ast.visitor.AnnotationClosureVisitor.replaceWithClosureClassReference(AnnotationClosureVisitor.java:250)
> {noformat}
> Form 4 fails with:
> {noformat}
> BUG! exception in phase 'semantic analysis' in source unit 'Account.groovy' 
> null
>       at 
> org.apache.groovy.contracts.ast.visitor.AnnotationClosureVisitor.replaceWithClosureClassReference(AnnotationClosureVisitor.java:236)
> {noformat}
> {{@Ensures}} and class-level {{@Invariant}} fail the same way with the same 
> bodies, and so does {{@Invariant}} on a loop (reported as "unexpected 
> NullPointerException").
> h3. Cause
> {{ExpressionUtils.getBooleanExpression}} builds the condition list from the 
> closure's statements and adds a null entry for every statement that is not an 
> expression statement, and {{ClosureExpressionValidator}} never checks 
> statement kinds, so the null reaches {{AssertStatementCreationUtility}}. For 
> form 4, {{ClosureExpression.getParameters()}} returns null (its documented 
> value for a closure with no parameters at all, as opposed to the empty array 
> for an implicit {{it}}) and {{AnnotationClosureVisitor}} passes it to 
> {{Arrays.asList}}.
> h3. Expected
> Forms 1 to 3 report a compile error that names the statement kind, for example
> {noformat}
> [groovy-contracts] Annotation closure may only contain boolean expressions; 
> return statements are not supported (e.g. use '@Requires({ argument1 > 0 })').
> {noformat}
> and form 4 compiles and behaves exactly like the closure without the arrow (a 
> {{PreconditionViolation}} for {{deposit(-1)}}). A {{return}} is rejected 
> rather than taken as the condition: each statement of the closure is its own 
> assertion, so a return has no meaning in that list.
> Reproduced on Groovy 6.0.0 and on master (df1fe66ed1). Pull request to follow.



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

Reply via email to