jsedding commented on code in PR #107:
URL:
https://github.com/apache/sling-org-apache-sling-resourceresolver/pull/107#discussion_r1404421763
##########
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 don't because if we change a `sling:alias` property from `["foo",
"bar"]` to `["baz", "foo", "bar"]`, then "baz" would be added to the end of
the list. That said, I believe the behaviour before your changes didn't account
for this scenario either. Therefore, I don't consider it a blocker.
--
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]