EvanYao826 opened a new pull request, #16272:
URL: https://github.com/apache/dubbo/pull/16272

   Fixes #16197
   
   ## Problem
   
   Hessian2 deserializes all small integers as `Integer`, causing 
`ClassCastException` when the expected type is `Byte`, `Short`, etc.
   
   ```java
   // Consumer sends
   List<Byte> byteList = List.of((byte)1, (byte)2, (byte)127);
   
   // Provider receives
   List<Integer> byteList = List.of(1, 2, 127); // ClassCastException!
   ```
   
   **Root cause**: Dubbo passes only the erased `Class` (e.g., `List.class`) to 
the serialization framework during request deserialization, discarding the 
generic `Type` (e.g., `List<Byte>`). Hessian2 has no way to know the expected 
element type.
   
   ## Fix
   
   In `Hessian2ObjectInput.readObjectOfType()`, after deserializing with the 
erased class, check if the declared type is a `ParameterizedType`. If so, 
convert collection/map elements to match the declared generic type arguments.
   
   ### Changes
   
   - `Hessian2ObjectInput.java`: Added `convertGenericType()` method that 
handles:
     - Collection types (`List`, `Set`) with element type conversion
     - Map types with key/value type conversion  
     - Numeric type narrowing (`Byte`, `Short`, `Float`, `Long`, `Double`, 
`Integer`)
     - Both boxed and primitive number types
   
   - `ReflectionMethodDescriptor.java`: Added `getGenericParameterTypes()` 
method to expose generic type information
   
   - `DecodeableRpcInvocation.java`: Pass generic `Type` instead of erased 
`Class` to deserialization
   
   - `Hessian2SerializationTest.java`: Added comprehensive tests for:
     - `List<Byte>`, `List<Short>`, `List<Float>`, `List<Long>`, `List<Double>`
     - `Map<String, Byte>`, `Map<String, Short>`
     - Mixed type collections


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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to