PDGGK opened a new pull request, #37365:
URL: https://github.com/apache/beam/pull/37365
## Summary
This PR fixes issue #37351 where DoFns with different generic type
parameters could incorrectly share cached invokers in
`ByteBuddyDoFnInvokerFactory`.
## Problem
The `ByteBuddyDoFnInvokerFactory` used `Class<?>` as the cache key for
generated DoFnInvoker constructors. This caused a cache collision when the same
DoFn class was used with different generic type parameters (e.g.,
`MyDoFn<String>` vs `MyDoFn<Integer>`), as they share the same raw class.
The generated bytecode includes type-specific casting operations (e.g.,
`TypeCasting.to(p.elementT().getRawType())`), so using the wrong cached invoker
could lead to incorrect behavior.
## Solution
- Added a new `InvokerCacheKey` class that includes both the DoFn class and
the `extraParameters` from the signature
- The `extraParameters` contain type information (e.g.,
`ElementParameter.elementT()`) that differs between DoFns with different
generic bindings
- Updated the cache to use this composite key instead of just `Class<?>`
## Changes
- `ByteBuddyDoFnInvokerFactory.java`: Added `InvokerCacheKey` inner class
and updated cache logic
- `DoFnInvokersTest.java`: Added 3 unit tests to verify the fix
## Testing
- All existing tests pass
- Added new tests:
- `testAnonymousDoFnsWithDifferentTypesGetDifferentInvokers`
- `testSameDoFnGetsCachedInvoker`
- `testDoFnSignaturesDistinguishElementTypes`
Fixes #37351
--
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]