[
https://issues.apache.org/jira/browse/GROOVY-12834?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18150902#comment-18150902
]
ASF GitHub Bot commented on GROOVY-12834:
-----------------------------------------
codecov-commenter commented on PR #3361:
URL: https://github.com/apache/groovy/pull/3361#issuecomment-7165135963
##
[Codecov](https://app.codecov.io/gh/apache/groovy/pull/3361?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.9678%. Comparing base
([`f1115f2`](https://app.codecov.io/gh/apache/groovy/commit/f1115f25db8950fb73d4c005407034ba7bf89231?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache))
to head
([`bdfe8db`](https://app.codecov.io/gh/apache/groovy/commit/bdfe8db468871e3490bb36424c402f1727c6eabf?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/3361?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
```diff
@@ Coverage Diff @@
## master #3361 +/- ##
==================================================
+ Coverage 74.9529% 74.9678% +0.0149%
- Complexity 48931 48941 +10
==================================================
Files 1768 1768
Lines 161256 161256
Branches 31743 31743
==================================================
+ Hits 120866 120890 +24
+ Misses 28977 28955 -22
+ Partials 11413 11411 -2
```
| [Files with missing
lines](https://app.codecov.io/gh/apache/groovy/pull/3361?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
| Coverage Δ | |
|---|---|---|
|
[...codehaus/groovy/classgen/asm/InvocationWriter.java](https://app.codecov.io/gh/apache/groovy/pull/3361?src=pr&el=tree&filepath=src%2Fmain%2Fjava%2Forg%2Fcodehaus%2Fgroovy%2Fclassgen%2Fasm%2FInvocationWriter.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3JjL21haW4vamF2YS9vcmcvY29kZWhhdXMvZ3Jvb3Z5L2NsYXNzZ2VuL2FzbS9JbnZvY2F0aW9uV3JpdGVyLmphdmE=)
| `86.7562% <100.0000%> (+0.5758%)` | :arrow_up: |
... and [12 files with indirect coverage
changes](https://app.codecov.io/gh/apache/groovy/pull/3361/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>
> null as boolean throws IllegalArgumentException with classic call sites
> -----------------------------------------------------------------------
>
> Key: GROOVY-12834
> URL: https://issues.apache.org/jira/browse/GROOVY-12834
> Project: Groovy
> Issue Type: Bug
> Components: Compiler
> Affects Versions: 5.1.3, 6.0.0
> Reporter: James Daugherty
> Priority: Major
>
> Coercing a null value to {{boolean}} with the {{as}} operator
> {code:groovy}
> class Holder {
> Object value
> }
> boolean present(Holder h) {
> h.value as boolean
> }
> assert !present(new Holder())
> {code}
> gives {{false}} on Groovy 4, and on Groovy 5 and later when the class is
> compiled for invokedynamic. Compiled with classic call sites ({{indy=false}})
> on Groovy 5 and later it throws:
> {noformat}
> java.lang.IllegalArgumentException: null to boolean
> {noformat}
> The result is the same in dynamic and in {{@CompileStatic}} code. Only the
> {{as}} form is affected: a cast ({{(boolean) x}}), an assignment to a
> {{boolean}}, a {{boolean}} return and Groovy truth ({{x ? true : false}},
> {{!!x}}) give {{false}} in every mode.
> ||Expression, value is null||4.0.33, indy||4.0.33, classic||5.x / 6.x /
> master, indy||5.x / 6.x / master, classic||
> |{{x as boolean}}|false|false|false|*IllegalArgumentException: null to
> boolean*|
> |{{(boolean) x}}|false|false|false|false|
> |{{boolean b = x}}|false|false|false|false|
> |{{x ? true : false}}|false|false|false|false|
> {{x as boolean}} is a common way to write "is this set", so an application
> that compiles without invokedynamic (the Grails default up to Grails 8) meets
> this at run time, at each such expression whose value happens to be null,
> after moving from Groovy 4 to Groovy 5.
> *Reproducer:*
> https://github.com/jdaugherty/groovy-null-as-primitive-reproducer
> ({{./gradlew -q reproduce}}) compiles and runs each form with 4.0.33, 5.1.3
> and 6.0.0, with invokedynamic and with classic call sites.
> *Cause:* the two bytecode writers coerce differently.
> {{InvocationWriter.coerce()}} (classic) passes the target type as written to
> {{ScriptBytecodeAdapter.asType(Object, Class)}}, so {{null as boolean}} calls
> {{NullObject.asType(boolean.class)}}. Since 5.0.0-alpha-3 that method rejects
> primitive types (it came in with the change for GROOVY-11196):
> {code:java}
> public Object asType(final Class c) {
> if (c.isPrimitive()) throw new IllegalArgumentException("null to " + c);
> return null;
> }
> {code}
> Before, it returned null and the cast to {{boolean}} that follows turned null
> into {{false}}. {{InvokeDynamicWriter.coerce()}} asks for the wrapper type
> instead, {{asType(Boolean)}}, and casts the result to {{boolean}}, so the
> check is never reached.
> *Suggested fix:* make the classic writer agree with the invokedynamic writer:
> in {{InvocationWriter.coerce()}}, call {{asType}} with the wrapper of a
> primitive target type and leave the conversion to the primitive to the cast
> that follows.
> Reproduced with classic call sites on 5.0.7, 5.1.3, 6.0.0 and master. Not
> reproduced on 4.0.33, or on any of these versions with invokedynamic.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)