daniellansun commented on PR #3333:
URL: https://github.com/apache/groovy/pull/3333#issuecomment-7235276447

   Thanks very much for the thoughtful review and prototype, @paulk-asert! 
Reusing Groovy's own dynamic selection machinery is a much cleaner direction 
than maintaining a separate set of overload rules.
   
   I've reworked the implementation in 8a8c215 along the lines you suggested:
   
   1. **Reused Groovy's dynamic selection & coercion**: Replaced the custom 
scoring, widening, and coercion logic with `ParameterTypes`, `CachedClass`, 
`MetaClassHelper.calculateParameterDistance`, and `CachedClass.coerceArgument`, 
extracted into a package-private `MBeanOperationResolver` to keep `GroovyMBean` 
focused without adding any public API.
   2. **Aligned `null` and dynamic Groovy semantics (and documented them 
explicitly)**: Adopted dynamic Groovy's distance rules—so `shape(null)` now 
selects `Object` over `String`, matching a regular dynamic call on a Groovy 
object. Among candidates with equal distance (such as sub-interfaces or 
covariant reference arrays), a strictly more specific signature wins via 
`Class.isAssignableFrom`; any remaining tie or unmatched call still falls back 
to the last registered operation in `MBeanInfo` order, while single-candidate 
operations keep the direct fast path. This behavior (along with calling 
`server().invoke(...)` when an exact signature is needed) is now documented in 
`GroovyMBean#invokeMethod` Javadoc and `jmx.adoc`.
   3. **Additional edge-case and performance hardening**:
      - Materialized `ParameterTypes` eagerly before lock-free publication via 
`AtomicReference`, and checked applicability via `CachedClass.isAssignableFrom` 
(plus rejecting `null` for primitive parameters) to avoid 
`ParameterTypes#isValidExactMethod`'s per-call synchronization.
      - Used copy-on-write `Arrays.copyOf(..., Object[].class)` when coercing 
or unwrapping `Wrapper` arguments so covariant arrays (e.g. `BigDecimal[]`, 
`GString[]`) cannot trigger `ArrayStoreException`, and kept selection/coercion 
under `GroovyMBean`'s existing `ignoreErrors` handling.
      - Refined `ClassLoader` resolution (trying the argument's loader first, 
then TCCL, `GroovyMBean`'s loader including bootstrap fallback, and other 
argument loaders) while caching standard-loader positive and negative misses 
(`UNRESOLVED_STANDARD`) without retaining foreign `ClassLoader` references.
   4. **Expanded tests**: Updated `Groovy2807` to assert the dynamic Groovy 
`null` and `Character` semantics explicitly (also fixing a latent 
`MBeanInfo`-order dependency in the earlier `num(Character)` assertion) and 
added coverage for SAM/`Closure`, `Wrapper`, covariant arrays, 
multi-`ClassLoader` isolation, error handling, and concurrent invocations.
   
   I've also updated the PR description so the intended dynamic Groovy 
selection rules are stated clearly up front. Please let me know if you have any 
further thoughts or suggestions!


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