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

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

commit e55575793d8570f959fbed2399f1877dbc96a915
Author: Julian Reschke <[email protected]>
AuthorDate: Mon Jun 2 15:54:10 2025 +0100

    SLING-12787: ResourceResolver: alias refactoring - use Resource instead of 
Path when getting aliases - fix recursion when Resource parent not accessible
---
 .../impl/mapping/ResourceMapperImpl.java           | 23 +++++++++++-----------
 .../impl/ResourceDecorationTest.java               |  2 +-
 2 files changed, 13 insertions(+), 12 deletions(-)

diff --git 
a/src/main/java/org/apache/sling/resourceresolver/impl/mapping/ResourceMapperImpl.java
 
b/src/main/java/org/apache/sling/resourceresolver/impl/mapping/ResourceMapperImpl.java
index 27dab795..0d32a7cd 100644
--- 
a/src/main/java/org/apache/sling/resourceresolver/impl/mapping/ResourceMapperImpl.java
+++ 
b/src/main/java/org/apache/sling/resourceresolver/impl/mapping/ResourceMapperImpl.java
@@ -27,6 +27,7 @@ import java.util.function.UnaryOperator;
 
 import jakarta.servlet.http.HttpServletRequest;
 import org.apache.sling.api.resource.Resource;
+import org.apache.sling.api.resource.ResourceUtil;
 import org.apache.sling.api.resource.mapping.ResourceMapper;
 import org.apache.sling.resourceresolver.impl.JcrNamespaceMangler;
 import org.apache.sling.resourceresolver.impl.ResourceResolverImpl;
@@ -238,23 +239,23 @@ public class ResourceMapperImpl implements ResourceMapper 
{
      */
     private void resolveAliases(@NotNull Resource resource, @NotNull 
PathGenerator pathGenerator) {
         Resource current = resource;
+        String path = current.getPath();
 
-        while (current != null) {
-            String name = current.getName();
+        while (!"/".equals(path)) {
+            String name = ResourceUtil.getName(path);
 
-            // read aliases only if it's not a jcr:content resource
-            Collection<String> aliases = name.equals("jcr:content") ? 
Collections.emptyList() : readAliases(current);
+            // read aliases only if it's not a jcr:content resource, and we 
actually have a resource
+            Collection<String> aliases =
+                    current == null || name.equals("jcr:content") ? 
Collections.emptyList() : readAliases(current);
 
-            // build the path from the name segments or aliases
+            // build the path segment from the name and the discoverd aliases
             pathGenerator.insertSegment(aliases, name);
 
-            // traverse up
-            current = current.getParent();
+            // current can already be or can become null here due to missing 
access rights
+            current = current != null ? current.getParent() : null;
 
-            // reached the root? -> stop traversing up
-            if (current != null && current.getParent() == null) {
-                current = null;
-            }
+            // traverse up
+            path = ResourceUtil.getParent(path);
         }
     }
 
diff --git 
a/src/test/java/org/apache/sling/resourceresolver/impl/ResourceDecorationTest.java
 
b/src/test/java/org/apache/sling/resourceresolver/impl/ResourceDecorationTest.java
index 11b7f660..c85ba4f5 100644
--- 
a/src/test/java/org/apache/sling/resourceresolver/impl/ResourceDecorationTest.java
+++ 
b/src/test/java/org/apache/sling/resourceresolver/impl/ResourceDecorationTest.java
@@ -33,7 +33,7 @@ import static org.junit.Assert.assertTrue;
 public class ResourceDecorationTest extends ResourceDecoratorTestBase {
 
     private static final String DECORATED_NAME = "decorated";
-    private static final String DECORATED_PATH = "/decorated";
+    private static final String DECORATED_PATH = "/decoratedPath";
 
     /** Wrap any resource so that its name is DECORATED_NAME */
     protected Resource wrapResourceForTest(Resource resource) {

Reply via email to