Fixed: Ensure that ‘MapContext’ preserves insertion order properties
(OFBIZ-10933) This fixes a regression introduced in revision 1837462. When pushing a ‘LinkedHashMap’ inside a ‘MapContext’, the iteration order of the ‘MapContext’ values was not corresponding to the insertion order of the embedded ‘LinkedHashMap’ which is important in the ‘ControllerConfig’ case where configuration elements are stored in ‘LinkedHashMap’ objects and the ‘include’ mechanism relies on ‘MapContext’. To avoid such regression in the future, a test reproducing the bug has been added. Thanks: Gil Portenseigne for investigating. git-svn-id: https://svn.apache.org/repos/asf/ofbiz/ofbiz-framework/trunk@1857818 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
@@ -28,6 +28,7 @@ import java.util.Collections;
|
||||
import java.util.Deque;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
@@ -213,8 +214,8 @@ public class MapContext<K, V> implements Map<K, V>, LocalizedMap<V> {
|
||||
@Override
|
||||
public Set<Map.Entry<K, V>> entrySet() {
|
||||
return entryStream()
|
||||
// Don't use Collectors#toSet() which does not use encounter order.
|
||||
.collect(collectingAndThen(toCollection(HashSet::new), Collections::unmodifiableSet));
|
||||
// Use LinkedHashSet for users relying on the insertion order of the inner maps.
|
||||
.collect(collectingAndThen(toCollection(LinkedHashSet::new), Collections::unmodifiableSet));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user