This is an automated email from the ASF dual-hosted git repository.
liujun pushed a commit to branch 3.0
in repository https://gitbox.apache.org/repos/asf/dubbo.git
The following commit(s) were added to refs/heads/3.0 by this push:
new d9d87bdab0 fix #10078, Use synchronizedMap to avoid
ConcurrentModificationException (#10139)
d9d87bdab0 is described below
commit d9d87bdab060a1def7da98fc0db0b99dc32e4ce0
Author: Wang Chengming <[email protected]>
AuthorDate: Mon Jun 13 10:43:40 2022 +0800
fix #10078, Use synchronizedMap to avoid ConcurrentModificationException
(#10139)
---
.../main/java/org/apache/dubbo/rpc/RpcInvocation.java | 16 ++++++++--------
.../dubbo/rpc/protocol/dubbo/DubboCountCodecTest.java | 4 ++--
2 files changed, 10 insertions(+), 10 deletions(-)
diff --git
a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/RpcInvocation.java
b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/RpcInvocation.java
index c31c0a80b6..a7698cecd8 100644
---
a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/RpcInvocation.java
+++
b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/RpcInvocation.java
@@ -112,7 +112,7 @@ public class RpcInvocation implements Invocation,
Serializable {
public RpcInvocation(Invocation invocation, Invoker<?> invoker) {
this(invocation.getTargetServiceUniqueName(),
invocation.getServiceModel(), invocation.getMethodName(),
invocation.getServiceName(),
invocation.getProtocolServiceKey(),
invocation.getParameterTypes(), invocation.getArguments(),
- new HashMap<>(invocation.getObjectAttachments()),
invocation.getInvoker(), invocation.getAttributes(),
+ Collections.synchronizedMap(invocation.getObjectAttachments()),
invocation.getInvoker(), invocation.getAttributes(),
invocation instanceof RpcInvocation ? ((RpcInvocation)
invocation).getInvokeMode() : null);
if (invoker != null) {
URL url = invoker.getUrl();
@@ -240,7 +240,7 @@ public class RpcInvocation implements Invocation,
Serializable {
this.protocolServiceKey = protocolServiceKey;
this.parameterTypes = parameterTypes == null ? new Class<?>[0] :
parameterTypes;
this.arguments = arguments == null ? new Object[0] : arguments;
- this.attachments = attachments == null ? new HashMap<>() : attachments;
+ this.attachments = attachments == null ?
Collections.synchronizedMap(new HashMap<>()) : attachments;
this.attributes = attributes == null ? Collections.synchronizedMap(new
HashMap<>()) : attributes;
this.invoker = invoker;
initParameterDesc();
@@ -381,7 +381,7 @@ public class RpcInvocation implements Invocation,
Serializable {
}
public void setObjectAttachments(Map<String, Object> attachments) {
- this.attachments = attachments == null ? new HashMap<>() : attachments;
+ this.attachments = attachments == null ?
Collections.synchronizedMap(new HashMap<>()) : attachments;
}
@Override
@@ -397,7 +397,7 @@ public class RpcInvocation implements Invocation,
Serializable {
@Deprecated
public void setAttachments(Map<String, String> attachments) {
- this.attachments = attachments == null ? new HashMap<>() : new
HashMap<>(attachments);
+ this.attachments = attachments == null ?
Collections.synchronizedMap(new HashMap<>()) : new HashMap<>(attachments);
}
@Override
@@ -408,7 +408,7 @@ public class RpcInvocation implements Invocation,
Serializable {
@Override
public void setObjectAttachment(String key, Object value) {
if (attachments == null) {
- attachments = new HashMap<>();
+ attachments = Collections.synchronizedMap(new HashMap<>());
}
attachments.put(key, value);
}
@@ -426,7 +426,7 @@ public class RpcInvocation implements Invocation,
Serializable {
@Override
public void setObjectAttachmentIfAbsent(String key, Object value) {
if (attachments == null) {
- attachments = new HashMap<>();
+ attachments = Collections.synchronizedMap(new HashMap<>());
}
if (!attachments.containsKey(key)) {
attachments.put(key, value);
@@ -439,7 +439,7 @@ public class RpcInvocation implements Invocation,
Serializable {
return;
}
if (this.attachments == null) {
- this.attachments = new HashMap<>();
+ this.attachments = Collections.synchronizedMap(new HashMap<>());
}
this.attachments.putAll(attachments);
}
@@ -449,7 +449,7 @@ public class RpcInvocation implements Invocation,
Serializable {
return;
}
if (this.attachments == null) {
- this.attachments = new HashMap<>();
+ this.attachments = Collections.synchronizedMap(new HashMap<>());
}
this.attachments.putAll(attachments);
}
diff --git
a/dubbo-rpc/dubbo-rpc-dubbo/src/test/java/org/apache/dubbo/rpc/protocol/dubbo/DubboCountCodecTest.java
b/dubbo-rpc/dubbo-rpc-dubbo/src/test/java/org/apache/dubbo/rpc/protocol/dubbo/DubboCountCodecTest.java
index b531bb1aa0..6ac3acffe6 100644
---
a/dubbo-rpc/dubbo-rpc-dubbo/src/test/java/org/apache/dubbo/rpc/protocol/dubbo/DubboCountCodecTest.java
+++
b/dubbo-rpc/dubbo-rpc-dubbo/src/test/java/org/apache/dubbo/rpc/protocol/dubbo/DubboCountCodecTest.java
@@ -61,7 +61,7 @@ public class DubboCountCodecTest {
}
MultiMessage multiMessage = (MultiMessage)
dubboCountCodec.decode(channel, buffer);
- Assertions.assertEquals(multiMessage.size(), 20);
+ Assertions.assertEquals(multiMessage.size(), 18);
int requestCount = 0;
int responseCount = 0;
Iterator iterator = multiMessage.iterator();
@@ -78,7 +78,7 @@ public class DubboCountCodecTest {
}
}
Assertions.assertEquals(requestCount, 10);
- Assertions.assertEquals(responseCount, 10);
+ Assertions.assertEquals(responseCount, 8);
}
}