You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by GitBox <gi...@apache.org> on 2022/04/25 12:15:06 UTC

[GitHub] [servicecomb-java-chassis] yhs0092 commented on issue #2801: InvocationContext 的 mergeContext 方法没有做好深拷贝保护

yhs0092 commented on issue #2801:
URL: https://github.com/apache/servicecomb-java-chassis/issues/2801#issuecomment-1108494034

   > typo? `输入参数中带出来了被输入的Invocation的内部属性` => `输入参数中带出来了被输出的Invocation的内部属性`
   > 
   > we'd better provider the code piece link.
   
   我可能表述得不好, 这是问题展示demo, 以`org.apache.servicecomb.core.Invocation`做例子:
   ```java
     public static void main(String[] args) {
       final Invocation i0 = new Invocation();
       i0.addContext("i0-k0","abc");
       i0.addContext("i0-k1","abc");
       final Invocation i1 = new Invocation();
       i1.addContext("i1-k0","def");
       i1.addContext("i1-k1","def");
       i1.addContext("i1-k2","def");
       i1.addContext("i1-k3","def");
   
       i0.mergeContext(i1);
       // 预期 i1 是输入参数, 其本身并不会受影响, 但实际发现 mergeContext 执行后 i1 自身的 context 也变了
       System.out.println(i0.getContext());
       System.out.println(i1.getContext());
       // 预期merge应该是深拷贝, 防止外部修改 i0 的数据, 但实际上只需修改 i1 就会引起 i0 的 context 变化
       i1.addContext("extra","ext-value");
       System.out.println(i0.getContext());
     }
   ```
   
   输出会是这个样子的:
   ```
   {i1-k2=def, i0-k1=abc, i1-k3=def, i1-k0=def, i1-k1=def, i0-k0=abc}
   {i1-k2=def, i0-k1=abc, i1-k3=def, i1-k0=def, i1-k1=def, i0-k0=abc}
   {i1-k2=def, i0-k1=abc, i1-k3=def, i1-k0=def, i1-k1=def, i0-k0=abc, extra=ext-value}
   ```


-- 
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: commits-unsubscribe@servicecomb.apache.org

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