This is an automated email from the ASF dual-hosted git repository.

reschke pushed a commit to branch 1.x
in repository 
https://gitbox.apache.org/repos/asf/sling-org-apache-sling-resourceresolver.git


The following commit(s) were added to refs/heads/1.x by this push:
     new f8de38e5 SLING-12758: remove redundant check for absolute path in 
alias (#171)
f8de38e5 is described below

commit f8de38e54ada701d771788062cf7b52c8b327c33
Author: Julian Reschke <[email protected]>
AuthorDate: Wed Apr 23 18:12:59 2025 +0200

    SLING-12758: remove redundant check for absolute path in alias (#171)
---
 .../resourceresolver/impl/ResourceResolverImpl.java   | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)

diff --git 
a/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverImpl.java
 
b/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverImpl.java
index 9b5f9201..f1e9c6fd 100644
--- 
a/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverImpl.java
+++ 
b/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverImpl.java
@@ -880,20 +880,21 @@ public class ResourceResolverImpl extends SlingAdaptable 
implements ResourceReso
         // we do not have a child with the exact name, so we look for
         // a child, whose alias matches the childName
         if (factory.getMapEntries().isOptimizeAliasResolutionEnabled()) {
-            logger.debug("getChildInternal: Optimize Alias Resolution is 
Enabled");
-            // optimization made in SLING-2521
+            final String parentPath = parent.getPath();
+            logger.debug(
+                    "getChildInternal: Optimize Alias Resolution is Enabled, 
looking up {} in {}",
+                    childName,
+                    parentPath);
+
+            // optimized alias resolution: aliases are cached by MapEntries
             final Optional<String> aliasedResourceName =
-                    
factory.getMapEntries().getAliasMap(parent.getPath()).entrySet().stream()
+                    
factory.getMapEntries().getAliasMap(parentPath).entrySet().stream()
                             .filter(e -> e.getValue().contains(childName))
                             .findFirst()
                             .map(Map.Entry::getKey);
             if (aliasedResourceName.isPresent()) {
-                final String aliasPath;
-                if (aliasedResourceName.get().startsWith("/")) {
-                    aliasPath = aliasedResourceName.get();
-                } else {
-                    aliasPath = parent.getPath() + '/' + 
aliasedResourceName.get();
-                }
+                // we know that MapEntries already has checked for valid 
aliases
+                final String aliasPath = parentPath + '/' + 
aliasedResourceName.get();
                 final Resource aliasedChild =
                         getAbsoluteResourceInternal(parent, 
ResourceUtil.normalize(aliasPath), EMPTY_PARAMETERS, true);
                 logger.debug("getChildInternal: Found Resource {} with alias 
{} to use", aliasedChild, childName);

Reply via email to