You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by li...@apache.org on 2020/05/27 05:58:50 UTC

[dubbo] branch master updated: fix object attachments iteration bug (#6210)

This is an automated email from the ASF dual-hosted git repository.

liujieqin 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 21e11e7  fix object attachments iteration bug (#6210)
21e11e7 is described below

commit 21e11e7baedc3065919c701b5a79db68f3d9f3d1
Author: ken.lj <ke...@gmail.com>
AuthorDate: Wed May 27 13:58:39 2020 +0800

    fix object attachments iteration bug (#6210)
    
    * fix object attachments iteration bug
---
 .../org/apache/dubbo/rpc/AttachmentsAdapter.java   | 48 ++++++++--------------
 1 file changed, 17 insertions(+), 31 deletions(-)

diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/AttachmentsAdapter.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/AttachmentsAdapter.java
index 873e7ae..1703792 100644
--- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/AttachmentsAdapter.java
+++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/AttachmentsAdapter.java
@@ -29,25 +29,25 @@ public class AttachmentsAdapter {
         private Map<String, Object> attachments;
 
         public ObjectToStringMap(Map<String, Object> attachments) {
+            for (Entry<String, Object> entry : attachments.entrySet()) {
+                String converResult = convert(entry.getValue());
+                if (converResult != null) {
+                    super.put(entry.getKey(), converResult);
+                }
+            }
             this.attachments = attachments;
         }
 
         @Override
-        public String get(Object key) {
-            Object obj = attachments.get(key);
-            return convert(obj);
-        }
-
-        @Override
         public String put(String key, String value) {
-            Object obj = attachments.put(key, value);
-            return convert(obj);
+            attachments.put(key, value);
+            return super.put(key, value);
         }
 
         @Override
         public String remove(Object key) {
-            Object obj = attachments.remove(key);
-            return convert(obj);
+            attachments.remove(key);
+            return super.remove(key);
         }
 
         private String convert(Object obj) {
@@ -56,31 +56,17 @@ public class AttachmentsAdapter {
             }
             return null; // or JSON.toString(obj);
         }
-    }
-
-    public static class StringToObjectMap extends HashMap<String, Object> {
-        private Map<String, String> attachments;
-
-        public StringToObjectMap(Map<String, String> attachments) {
-            this.attachments = attachments;
-        }
 
         @Override
-        public Object get(Object key) {
-            return attachments.get(key);
-        }
-
-        @Override
-        public Object put(String key, Object value) {
-            if (value instanceof String) {
-                return attachments.put(key, (String) value);
-            }
-            return null; // or JSON.toString(obj);
+        public void clear() {
+            attachments.clear();
+            super.clear();
         }
 
         @Override
-        public Object remove(Object key) {
-            return attachments.remove(key);
+        public void putAll(Map<? extends String, ? extends String> map) {
+            attachments.putAll(map);
+            super.putAll(map);
         }
     }
-}
+}
\ No newline at end of file