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

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

jdaugherty commented on PR #3361:
URL: https://github.com/apache/groovy/pull/3361#issuecomment-7166356902

   @paulk-asert could you retrigger the failed `lts (17, macos-latest)` job? 
It's a CI flake unrelated to this change — no test failed (27,355 passed, 0 
failed); the `:groovy-sql:test` task errored before running:
   
   ```
   Execution failed for task ':groovy-sql:test'
   > Could not read path 
'/Users/runner/.groovy/grapes/resolved-caller-all-caller-working70.xml'.
   ```
   
   The same failure hit an unrelated branch on Linux two days ago ([run 
45098713773](https://github.com/apache/groovy/actions/runs/45098713773), 
`:groovy-csv:test`, `...working37.xml`).
   
   **Cause:** a race between two concurrent Test tasks.
   1. With `groovy.grape.bridge-cache=true`, each Test task's `doFirst` copies 
the runner's real `~/.groovy/grapes` into its own grape root 
(`org.apache.groovy-tested.gradle`).
   2. Meanwhile, root `:test` runs `@ForkedJvm` tests that `@Grab` without 
inheriting `grape.root`/`user.home` (`ExtensionModuleTest`, 
`STCExtensionMethodsTest`, `Groovy11046`, the Spock test in 
`TraitASTTransformationTest`), so those child JVMs resolve against the runner's 
real `~/.groovy/grapes`.
   3. Each resolution creates a transient 
`resolved-caller-all-caller-workingNN.xml` and `GrapeIvy` deletes it right 
after. If the bridge copy lists the file and it's gone before being read, 
Gradle fails the task.
   
   **Proposed fix:** Gradle only throws on a vanished file when the copy spec 
would include it, so excluding Ivy's transient files from both bridge copies is 
sufficient:
   
   ```groovy
   exclude '**/*.lck', '**/*.lastUpdated', '**/resolved-caller-*', '**/*.part'
   ```
   
   Optionally, those forked tests could also get `inheritProperties = 
['grape.root', 'user.home']` (as `GrabResolverTest` already has) so they stop 
writing to the real `~/.groovy/grapes` at all.
   




> 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)

Reply via email to