jdaugherty opened a new pull request, #3085:
URL: https://github.com/apache/groovy/pull/3085

   A cast call site reused `MethodSelector.setGuards()`, which guards a 
`GroovyObject` receiver with its metaclass, so every cast of a `GroovyObject` 
called `getMetaClass()` on the value: once to build the guard and again on each 
invocation through it. A class-based proxy of a Groovy class, such as a Spring 
scoped proxy, forwards `getMetaClass()` to its target, so `Report report = 
proxy` failed outside the proxy's scope, where classic call sites call nothing 
on the value.
   
   Only a cast to boolean selects a method, `asBoolean`, through the metaclass; 
every other cast is decided by the class of the value, which the argument 
guards and the class switch point already cover. `CastSelector` now keeps the 
receiver metaclass guard for that case only.
   
   `org.codehaus.groovy.vmplugin.v8.IndyCastReceiverMetaClassTest` checks that 
a cast of a value that already has the target type makes no `getMetaClass()` 
call and succeeds when `getMetaClass()` throws, that a cast to boolean still 
selects `asBoolean` through each value's metaclass, and that a cast site still 
rejects a value of another class. It fails without the fix.
   
   - Jira: [GROOVY-12557](https://issues.apache.org/jira/browse/GROOVY-12557)
   - Reproducer: 
https://github.com/jdaugherty/groovy-indy-cast-getmetaclass-reproducer
   - Backport to `GROOVY_6_0_X`: 
https://github.com/jdaugherty/groovy/commit/bc97fa58f126beb18d67013110cc5488b198eb16,
 on the branch 
[`GROOVY-12557-6_0_X`](https://github.com/jdaugherty/groovy/tree/GROOVY-12557-6_0_X).
   - Backport to `GROOVY_5_1_X`: 
https://github.com/jdaugherty/groovy/commit/0300e782ece81007601006722560b59fa9ba670c,
 on the branch 
[`GROOVY-12557-5_1_X`](https://github.com/jdaugherty/groovy/tree/GROOVY-12557-5_1_X).
 The 5.1.x `Selector` predates the per-class switch points, so the guard change 
is applied by hand there.
   
   It reproduces on 4.0.33, 5.1.3, 6.0.0 and master with invokedynamic, and not 
with classic call sites. 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]

Reply via email to