kwin commented on code in PR #107:
URL: 
https://github.com/apache/sling-org-apache-sling-resourceresolver/pull/107#discussion_r1403263503


##########
src/main/java/org/apache/sling/resourceresolver/impl/mapping/MapEntries.java:
##########
@@ -1243,24 +1236,20 @@ private boolean loadAlias(final Resource resource, 
Map<String, Map<String, Strin
 
             if (aliasArray != null) {
                 log.debug("Found alias, total size {}", aliasArray.length);
+                // the order matters here, the first alias in the array must 
come first
                 for (final String alias : aliasArray) {
                     if (isAliasValid(alias)) {
                         log.warn("Encountered invalid alias {} under parent 
path {}. Refusing to use it.", alias, parentPath);
                     } else {
-                        Map<String, String> parentMap = map.get(parentPath);
-
-                        if (parentMap == null) {
-                            parentMap = new LinkedHashMap<>();
-                            map.put(parentPath, parentMap);
-                        }
-
-                        String current = parentMap.get(alias);
-                        if (current != null) {
+                        ConcurrentMap<String, List<String>> parentMap = 
map.computeIfAbsent(parentPath, key -> new ConcurrentHashMap<>());
+                        Optional<String> currentResourceName = 
parentMap.entrySet().stream().filter(entry -> 
entry.getValue().contains(alias)).findFirst().map(Map.Entry::getKey);
+                        if (currentResourceName.isPresent()) {
                             log.warn(
                                     "Encountered duplicate alias {} under 
parent path {}. Refusing to replace current target {} with {}.",
-                                    alias, parentPath, current, resourceName);
+                                    alias, parentPath, 
currentResourceName.get(), resourceName);
                         } else {
-                            parentMap.put(alias, resourceName);
+                            List<String> existingAliases = 
parentMap.computeIfAbsent(resourceName, name -> new CopyOnWriteArrayList<>());
+                            existingAliases.add(alias);

Review Comment:
   I think we do because we loop through the value in the order they are given 
in the property 
(https://github.com/apache/sling-org-apache-sling-resourceresolver/pull/107/files/97ca6165edfc7c913575d7ac65b10813e6c9acba#diff-b8232d361560d98697fcb8774c43f8f4a33e213a1c892171d339f956ef73df04R1240).
 Why do you want to replicate the logic from `CopyOnWriteArrayList`. Important 
for me is that this is ordered not so much that it doesn't contain duplicates, 
therefore I went for List<> instead of SortedSet<>



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

Reply via email to