You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by "AlbumenJ (via GitHub)" <gi...@apache.org> on 2023/05/11 11:01:13 UTC

[GitHub] [dubbo] AlbumenJ commented on a diff in pull request #12286: Fix ClassCastException caused by 2.x's filter in some condition

AlbumenJ commented on code in PR #12286:
URL: https://github.com/apache/dubbo/pull/12286#discussion_r1190999056


##########
dubbo-compatible/src/main/java/com/alibaba/dubbo/rpc/RpcResult.java:
##########
@@ -0,0 +1,115 @@
+package com.alibaba.dubbo.rpc;
+
+import java.io.Serializable;
+import java.util.HashMap;
+import java.util.Map;
+
+@Deprecated
+public class RpcResult extends Result.AbstractResult implements Serializable {
+    private static final long serialVersionUID = -6925924956850004727L;
+    private Object result;
+    private Throwable exception;
+    private Map<String, String> attachments = new HashMap();
+
+    public RpcResult() {
+    }
+
+    public RpcResult(Object result) {
+        this.result = result;
+    }
+
+    public RpcResult(Throwable exception) {
+        this.exception = exception;
+    }
+
+    public Object recreate() throws Throwable {
+        if (this.exception != null) {
+            throw this.exception;
+        } else {
+            return this.result;
+        }
+    }
+
+    /** @deprecated */
+    @Deprecated
+    public Object getResult() {
+        return this.getValue();
+    }
+
+    /** @deprecated */
+    @Deprecated
+    public void setResult(Object result) {
+        this.setValue(result);
+    }
+
+    public Object getValue() {
+        return this.result;
+    }
+
+    public void setValue(Object value) {
+        this.result = value;
+    }
+
+    public Throwable getException() {
+        return this.exception;
+    }
+
+    public void setException(Throwable e) {
+        this.exception = e;
+    }
+
+    public boolean hasException() {
+        return this.exception != null;
+    }
+
+    public Map<String, String> getAttachments() {
+        return this.attachments;
+    }
+
+    public void setAttachments(Map<String, String> map) {
+        this.attachments = (Map)(map == null ? new HashMap() : map);
+    }
+
+    public void addAttachments(Map<String, String> map) {
+        if (map != null) {
+            if (this.attachments == null) {
+                this.attachments = new HashMap();
+            }
+
+            this.attachments.putAll(map);
+        }
+
+    }
+
+    public String getAttachment(String key) {
+        return (String)this.attachments.get(key);
+    }
+
+    public String getAttachment(String key, String defaultValue) {
+        String result = (String)this.attachments.get(key);
+        if (result == null || result.length() == 0) {
+            result = defaultValue;
+        }
+
+        return result;
+    }
+
+    public void setAttachment(String key, String value) {
+        this.attachments.put(key, value);
+    }
+
+    @Override
+    public void setAttachment(String key, Object value) {
+
+    }
+
+    @Override
+    public void setObjectAttachment(String key, Object value) {
+
+    }
+
+    public String toString() {
+        return "RpcResult [result=" + this.result + ", exception=" + this.exception + "]";
+    }
+}
+

Review Comment:
   ```suggestion
   public class RpcResult extends AppResponse implements com.alibaba.dubbo.rpc.Result {
       public RpcResult() {
       }
   
       public RpcResult(Object result) {
           super(result);
       }
   
       public RpcResult(Throwable exception) {
           super(exception);
       }
   }
   
   ```



-- 
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: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org