rootvector2 commented on code in PR #719:
URL:
https://github.com/apache/commons-collections/pull/719#discussion_r3681155005
##########
src/main/java/org/apache/commons/collections4/properties/OrderedProperties.java:
##########
@@ -134,6 +211,37 @@ public synchronized Object merge(final Object key, final
Object value,
return merge;
}
+ /**
+ * Creates an iterator over the keys in insertion order whose {@link
Iterator#remove()} also removes the mapping.
+ *
+ * @return A new iterator.
+ */
+ private Iterator<Object> orderedKeysIterator() {
+ final Iterator<Object> iterator = orderedKeys.iterator();
+ return new Iterator<Object>() {
+
+ private Object last;
+
+ @Override
+ public boolean hasNext() {
+ return iterator.hasNext();
+ }
+
+ @Override
+ public Object next() {
+ last = iterator.next();
+ return last;
+ }
+
+ @Override
+ public void remove() {
+ // Not remove(Object), which would edit orderedKeys while this
iterator walks it.
+ iterator.remove();
+ OrderedProperties.super.remove(last);
+ }
Review Comment:
Fixed in 0f0e373. `iterator.remove()` was the one `orderedKeys` write
outside the monitor; the combined `orderedKeys` + map removal now runs inside
`synchronized (OrderedProperties.this)`.
--
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]