jdaugherty opened a new pull request, #3361: URL: https://github.com/apache/groovy/pull/3361
Since 5.0.0-alpha-3, `x as boolean` on a null value throws `IllegalArgumentException: null to boolean` when the class is compiled with classic call sites. With invokedynamic, and on Groovy 4 in both modes, it is `false`. Dynamic and `@CompileStatic` code behave the same; casts, assignments and Groovy truth are not affected. `InvocationWriter.coerce()` passed the target type as written to `ScriptBytecodeAdapter.asType()`, so the call reached `NullObject.asType(boolean.class)`, which rejects primitive types since the change for GROOVY-11196. `InvokeDynamicWriter.coerce()` asks for the wrapper type and lets the cast that follows convert to the primitive. The classic writer now does the same. With classic call sites, `null as int` consequently fails as it does with invokedynamic, with a `NullPointerException` from the unboxing instead of `IllegalArgumentException: null to int`. `bugs.Groovy12834` coerces a null, an empty and a non-empty value to `boolean` in dynamic and in `@CompileStatic` code, with invokedynamic and with classic call sites, and coerces non-null values to `int` and `char`. The two classic `boolean` cases fail without the fix. - Jira: [GROOVY-12834](https://issues.apache.org/jira/browse/GROOVY-12834) - Reproducer: https://github.com/jdaugherty/groovy-null-as-primitive-reproducer - Backport to `GROOVY_6_0_X`: https://github.com/jdaugherty/groovy/commit/c0b1330cfbfde3f58474815e8037eca4b0d34dc2, on the branch [`GROOVY-12834-6_0_X`](https://github.com/jdaugherty/groovy/tree/GROOVY-12834-6_0_X). - Backport to `GROOVY_5_1_X`: https://github.com/jdaugherty/groovy/commit/514673a59a72f3a20b162c6e3ed462c3357a41f0, on the branch [`GROOVY-12834-5_1_X`](https://github.com/jdaugherty/groovy/tree/GROOVY-12834-5_1_X). Reproduced on 5.0.7, 5.1.3, 6.0.0 and master with classic call sites only; 4.0.33 is not affected. Could this be backported to 6.0.x and 5.x once it is merged? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
