gnodet-bot commented on code in PR #26852:
URL: https://github.com/apache/camel/pull/26852#discussion_r4093343024
##########
core/camel-support/src/main/java/org/apache/camel/support/CopyOnWriteHeadersMap.java:
##########
@@ -485,6 +488,55 @@ public String toString() {
/**
* A COW-aware Set wrapper for entrySet() that triggers copy-on-write for
mutating operations.
*/
Review Comment:
🐛 **Orphaned Javadoc block:** This `/**...A COW-aware Set wrapper...*/`
block used to precede `CopyOnWriteEntrySet` and documented it. After inserting
`CopyOnWriteEntry` between this block and `CopyOnWriteEntrySet`, the Javadoc
tool will attach this comment to `CopyOnWriteEntry` instead — wrong
documentation on the wrong class.
Move (or copy) this block immediately above `CopyOnWriteEntrySet`, and let
`CopyOnWriteEntry`'s own `/**` stand alone:
```suggestion
```
Delete these three lines (the orphaned block) here, and add `/** A COW-aware
Set wrapper for entrySet() that triggers copy-on-write for mutating operations.
*/` just above `private class CopyOnWriteEntrySet`.
##########
core/camel-support/src/main/java/org/apache/camel/support/CopyOnWriteHeadersMap.java:
##########
@@ -505,14 +557,27 @@ public boolean contains(Object o) {
@Override
public Object[] toArray() {
+ if (shared) {
+ // the entries of a shared map must be wrapped, so setValue
does not change the shared map
+ return toList().toArray();
+ }
return delegate.entrySet().toArray();
}
@Override
public <T> T[] toArray(T[] a) {
+ if (shared) {
+ return toList().toArray(a);
+ }
return delegate.entrySet().toArray(a);
}
Review Comment:
⚠️ **Missing test coverage for `toArray(T[])`:** Both `toArray()` and
`toArray(T[] a)` were modified to wrap entries when shared, but only
`toArray()` (zero-arg) is tested by `testCopyOnWriteEntrySetToArraySetValue()`.
Add a parallel test using `toArray(new Object[0])` or `toArray(new
Map.Entry[0])` to verify the typed-array path triggers COW correctly.
--
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]