GlobalStar117 opened a new pull request, #37352:
URL: https://github.com/apache/beam/pull/37352

   ## Summary
   
   This PR fixes the cache collision issue in `ByteBuddyDoFnInvokerFactory` 
where DoFns with different generic types but the same raw class would 
incorrectly share cached invokers.
   
   **Fixes:** #37351
   
   ## Changes
   
   1. **Changed cache key from `Class<?>` to `DoFnSignature`**: Using the full 
signature as the key ensures that DoFns with different signatures (including 
those that differ only in generic type parameters when type information is 
preserved) receive correctly generated invokers.
   
   2. **Added test case**: Verifies that anonymous DoFn subclasses with 
different generic types produce different invokers.
   
   ## Explanation
   
   Previously, the cache was keyed solely on the DoFn class (`Class<?>`), which 
caused collisions when the same DoFn class was used with different generic 
types. Due to Java type erasure, `MyDoFn<String>` and `MyDoFn<Integer>` share 
the same raw class.
   
   By using `DoFnSignature` as the cache key (which is an `@AutoValue` class 
with proper equals/hashCode implementation), we ensure that:
   - DoFns with the same signature share the cached invoker (correct behavior)
   - DoFns with different signatures get different invokers (fixes the bug)
   
   This is a defensive fix that ensures correctness when type information IS 
preserved (e.g., through anonymous subclasses) while maintaining efficiency for 
the common case where signatures are identical.
   
   ## Testing
   
   - Added unit test `testGenericDoFnCacheKeyingWithAnonymousSubclasses` to 
verify different anonymous DoFn classes produce different invokers
   
   ---
   
   [Gittensor contribution - GlobalStar117]


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