CuSO41108 opened a new issue, #16594:
URL: https://github.com/apache/dubbo/issues/16594

   ## Bug description
   
   `RpcContext#setObjectAttachment(String, Object)` and the legacy 
`RpcContext#getAttachment(String)` disagree about what an attachment can be.
   
   `setObjectAttachment` / `getObjectAttachment` accept arbitrary objects, but 
the String-based accessor is backed by `RpcContextAttachment#getAttachment`, 
which only returns values that are `instanceof String`:
   
   ```java
   // RpcContextAttachment
   public String getAttachment(String key) {
       Object value = attachments.get(key);
       if (value instanceof String) {
           return (String) value;
       }
       return null; // or JSON.toString(value);
   }
   ```
   
   So when a value is published with the object-based API, a legacy caller gets 
`null`.
   
   Worse, `RpcContext#getAttachment` falls back to the server attachment 
whenever the client lookup comes back empty, so if the *other* side happens to 
hold a value under the same key, that value is returned instead — the caller 
silently reads an attachment that was never set on its own side.
   
   ## Steps to reproduce
   
   ```java
   RpcContext context = RpcContext.getContext();
   context.setObjectAttachment("id", 12345L);
   
   context.getObjectAttachment("id"); // 12345L  -> ok
   context.getAttachment("id");       // null    -> the legacy API cannot see it
   ```
   
   Client/server mix-up:
   
   ```java
   RpcContext.getServerAttachment().setObjectAttachment("id", "server-value");
   RpcContext.getClientAttachment().setObjectAttachment("id", 42L);
   
   RpcContext.getContext().getAttachment("id"); // "server-value" -> wrong, the 
client set 42L
   ```
   
   ## Expected behavior
   
   The legacy accessor should return a String representation of the attachment 
instead of `null`, so code written against the 2.x API keeps working when the 
value is published through the object-based API. `getObjectAttachment` must 
keep returning the original value with its original type.
   
   The `// TODO compatible with previous` marker in 
`RpcContext#setObjectAttachment` refers to exactly this gap.
   
   ## Affected versions
   
   3.3.x
   


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to