This is an automated email from the ASF dual-hosted git repository.
albumenj pushed a commit to branch 3.3
in repository https://gitbox.apache.org/repos/asf/dubbo.git
The following commit(s) were added to refs/heads/3.3 by this push:
new 542479ba8d Fix ParameterizedType in SERVER_STREAM (#14763)
542479ba8d is described below
commit 542479ba8d023290339c9efc7c6bd0adfb2fc974
Author: Albumen Kevin <[email protected]>
AuthorDate: Tue Oct 22 16:10:44 2024 +0800
Fix ParameterizedType in SERVER_STREAM (#14763)
---
.../remoting/http12/message/MethodMetadata.java | 24 ++++++++++++++--------
1 file changed, 16 insertions(+), 8 deletions(-)
diff --git
a/dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/message/MethodMetadata.java
b/dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/message/MethodMetadata.java
index 241d0c42bd..7f87edafbc 100644
---
a/dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/message/MethodMetadata.java
+++
b/dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/message/MethodMetadata.java
@@ -21,6 +21,7 @@ import org.apache.dubbo.rpc.model.ReflectionMethodDescriptor;
import org.apache.dubbo.rpc.model.StubMethodDescriptor;
import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
public class MethodMetadata {
@@ -64,18 +65,18 @@ public class MethodMetadata {
case CLIENT_STREAM:
case BI_STREAM:
actualRequestTypes = new Class<?>[] {
- (Class<?>)
- ((ParameterizedType)
method.getMethod().getGenericReturnType()).getActualTypeArguments()[0]
+ obtainActualTypeInStreamObserver(
+ ((ParameterizedType)
method.getMethod().getGenericReturnType()).getActualTypeArguments()[0])
};
- actualResponseType =
- (Class<?>) ((ParameterizedType)
method.getMethod().getGenericParameterTypes()[0])
- .getActualTypeArguments()[0];
+ actualResponseType = obtainActualTypeInStreamObserver(
+ ((ParameterizedType)
method.getMethod().getGenericParameterTypes()[0])
+ .getActualTypeArguments()[0]);
return new MethodMetadata(actualRequestTypes,
actualResponseType);
case SERVER_STREAM:
actualRequestTypes = new Class[]
{method.getMethod().getParameterTypes()[0]};
- actualResponseType =
- (Class<?>) ((ParameterizedType)
method.getMethod().getGenericParameterTypes()[1])
- .getActualTypeArguments()[0];
+ actualResponseType = obtainActualTypeInStreamObserver(
+ ((ParameterizedType)
method.getMethod().getGenericParameterTypes()[1])
+ .getActualTypeArguments()[0]);
return new MethodMetadata(actualRequestTypes,
actualResponseType);
case UNARY:
actualRequestTypes = method.getParameterClasses();
@@ -84,4 +85,11 @@ public class MethodMetadata {
}
throw new IllegalStateException("Can not reach here");
}
+
+ static Class<?> obtainActualTypeInStreamObserver(Type
typeInStreamObserver) {
+ return (Class<?>)
+ (typeInStreamObserver instanceof ParameterizedType
+ ? ((ParameterizedType)
typeInStreamObserver).getRawType()
+ : typeInStreamObserver);
+ }
}