Copilot commented on code in PR #8140:
URL: https://github.com/apache/incubator-seata/pull/8140#discussion_r3403878022


##########
integration-tx-api/src/main/java/org/apache/seata/rm/tcc/api/BusinessActionContext.java:
##########
@@ -253,4 +287,179 @@ public String toString() {
                 .append("]");
         return sb.toString();
     }
+
+    /**
+     * The tracked action context map.
+     */
+    private static final class TrackedActionContextMap extends 
AbstractMap<String, Object> implements Serializable {
+
+        private static final long serialVersionUID = 1L;
+
+        private final BusinessActionContext owner;
+
+        private final Map<String, Object> delegate;
+
+        private TrackedActionContextMap(BusinessActionContext owner) {
+            this.owner = owner;
+            this.delegate = new HashMap<>(8);
+        }
+
+        private TrackedActionContextMap(BusinessActionContext owner, 
Map<String, Object> source) {
+            this.owner = owner;
+            this.delegate = new HashMap<>(source);
+        }
+
+        @Override
+        public Object put(String key, Object value) {
+            boolean hadKey = delegate.containsKey(key);
+            Object previousValue = delegate.put(key, value);
+            if (!hadKey || !Objects.equals(previousValue, value)) {
+                owner.markUpdatedOnActionContextMutation();
+            }
+            return previousValue;
+        }
+
+        @Override
+        public void putAll(Map<? extends String, ? extends Object> m) {
+            Objects.requireNonNull(m, "m");
+            if (m.isEmpty()) {
+                return;
+            }
+            for (Map.Entry<? extends String, ? extends Object> entry : 
m.entrySet()) {
+                put(entry.getKey(), entry.getValue());
+            }
+        }
+
+        @Override
+        public Object remove(Object key) {
+            boolean hadKey = delegate.containsKey(key);
+            Object previousValue = delegate.remove(key);
+            if (hadKey) {
+                owner.markUpdatedOnActionContextMutation();
+            }
+            return previousValue;
+        }
+
+        @Override
+        public void clear() {
+            if (!delegate.isEmpty()) {
+                delegate.clear();
+                owner.markUpdatedOnActionContextMutation();
+            }
+        }
+
+        @Override
+        public Set<Entry<String, Object>> entrySet() {
+            return new AbstractSet<Entry<String, Object>>() {
+                @Override
+                public Iterator<Entry<String, Object>> iterator() {
+                    Iterator<Entry<String, Object>> iterator =
+                            delegate.entrySet().iterator();
+                    return new Iterator<Entry<String, Object>>() {
+                        private boolean canRemove;
+
+                        @Override
+                        public boolean hasNext() {
+                            return iterator.hasNext();
+                        }
+
+                        @Override
+                        public Entry<String, Object> next() {
+                            Entry<String, Object> current = iterator.next();
+                            canRemove = true;
+                            return new TrackingEntry(current);
+                        }
+
+                        @Override
+                        public void remove() {
+                            iterator.remove();
+                            if (canRemove) {
+                                owner.markUpdatedOnActionContextMutation();
+                            }
+                            canRemove = false;
+                        }
+                    };
+                }
+
+                // The following are read-only methods that delegate directly 
to the native Map.

Review Comment:
   The comment says the following methods are "read-only", but the block 
includes mutating operations (e.g., `remove`). This can confuse future 
maintainers about what is expected to trigger tracking.



-- 
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