You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by al...@apache.org on 2021/02/23 16:17:03 UTC
[dubbo] branch master updated: fix Exception stack information
acquisition optimization #6984 (#6985)
This is an automated email from the ASF dual-hosted git repository.
albumenj pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/dubbo.git
The following commit(s) were added to refs/heads/master by this push:
new 3c9cd79 fix Exception stack information acquisition optimization #6984 (#6985)
3c9cd79 is described below
commit 3c9cd79001ed416c8992c14dc0686124ba07467c
Author: huazhongming <cr...@gmail.com>
AuthorDate: Wed Feb 24 00:16:48 2021 +0800
fix Exception stack information acquisition optimization #6984 (#6985)
* fix Exception stack information acquisition optimization #6984
* delete useless import
---
.../src/main/java/org/apache/dubbo/rpc/AppResponse.java | 15 ++++-----------
.../apache/dubbo/rpc/proxy/InvokerInvocationHandler.java | 12 ++++++++++++
2 files changed, 16 insertions(+), 11 deletions(-)
diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/AppResponse.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/AppResponse.java
index 7ebff3f..4cff355 100644
--- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/AppResponse.java
+++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/AppResponse.java
@@ -16,7 +16,8 @@
*/
package org.apache.dubbo.rpc;
-import java.lang.reflect.Field;
+import org.apache.dubbo.rpc.proxy.InvokerInvocationHandler;
+
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
@@ -32,7 +33,7 @@ import java.util.function.Function;
* <li>AsyncRpcResult is the object that is actually passed in the call chain</li>
* <li>AppResponse only simply represents the business result</li>
* </ul>
- *
+ * <p>
* The relationship between them can be described as follow, an abstraction of the definition of AsyncRpcResult:
* <pre>
* {@code
@@ -71,15 +72,7 @@ public class AppResponse implements Result {
if (exception != null) {
// fix issue#619
try {
- // get Throwable class
- Class clazz = exception.getClass();
- while (!clazz.getName().equals(Throwable.class.getName())) {
- clazz = clazz.getSuperclass();
- }
- // get stackTrace value
- Field stackTraceField = clazz.getDeclaredField("stackTrace");
- stackTraceField.setAccessible(true);
- Object stackTrace = stackTraceField.get(exception);
+ Object stackTrace = InvokerInvocationHandler.stackTraceField.get(exception);
if (stackTrace == null) {
exception.setStackTrace(new StackTraceElement[0]);
}
diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/proxy/InvokerInvocationHandler.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/proxy/InvokerInvocationHandler.java
index 69f1d06..6e43c52 100644
--- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/proxy/InvokerInvocationHandler.java
+++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/proxy/InvokerInvocationHandler.java
@@ -26,6 +26,7 @@ import org.apache.dubbo.rpc.RpcInvocation;
import org.apache.dubbo.rpc.model.ApplicationModel;
import org.apache.dubbo.rpc.model.ConsumerModel;
+import java.lang.reflect.Field;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
@@ -39,6 +40,17 @@ public class InvokerInvocationHandler implements InvocationHandler {
private URL url;
private String protocolServiceKey;
+ public static Field stackTraceField;
+
+ static {
+ try {
+ stackTraceField = Throwable.class.getDeclaredField("stackTrace");
+ stackTraceField.setAccessible(true);
+ } catch (NoSuchFieldException e) {
+ // ignore
+ }
+ }
+
public InvokerInvocationHandler(Invoker<?> handler) {
this.invoker = handler;
this.url = invoker.getUrl();