Commit 4d337b6
committed
[Java] Fix DoFnInvoker cache collision for generic types (with fallback)
This PR fixes a critical issue where ByteBuddyDoFnInvokerFactory failed to distinguish between different generic instantiations of the same DoFn class (e.g., MyFn<String> vs MyFn<Integer>).
1. Cache Key Strategy: Introduced InvokerCacheKey to include input/output TypeDescriptors in the cache lookup.
2. Class Naming: Updated generateInvokerClass to append a type-based hash suffix to ensure unique class names.
3. Robustness (The Fix): Added defensive try-catch blocks when accessing TypeDescriptors.
- Some internal transforms (like MapElements) throw IllegalStateException if getOutputTypeDescriptor() is called after serialization.
- In these cases, the factory now gracefully falls back to using Object.class (legacy behavior), ensuring backward compatibility for transforms that do not retain type information at runtime.
Fixes #373511 parent 4f60c59 commit 4d337b6
1 file changed
Lines changed: 19 additions & 5 deletions
File tree
- sdks/java/core/src/main/java/org/apache/beam/sdk/transforms/reflect
Lines changed: 19 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
318 | 318 | | |
319 | 319 | | |
320 | 320 | | |
321 | | - | |
322 | | - | |
323 | | - | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
324 | 332 | | |
325 | 333 | | |
326 | 334 | | |
327 | | - | |
328 | | - | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
329 | 343 | | |
330 | 344 | | |
331 | 345 | | |
| |||
0 commit comments