This is an automated email from the ASF dual-hosted git repository.
reschke pushed a commit to branch master
in repository
https://gitbox.apache.org/repos/asf/sling-org-apache-sling-resourceresolver.git
The following commit(s) were added to refs/heads/master by this push:
new 0cc16ff3 SLING-12823: alias refactoring - avoid getting the parent
resource when path sufficient (#184)
0cc16ff3 is described below
commit 0cc16ff3c2c127bd46f17999f0c931cceee42e54
Author: Julian Reschke <[email protected]>
AuthorDate: Thu Jun 5 16:39:09 2025 +0200
SLING-12823: alias refactoring - avoid getting the parent resource when
path sufficient (#184)
---
.../impl/mapping/AliasHandler.java | 32 ++++++++--------------
1 file changed, 12 insertions(+), 20 deletions(-)
diff --git
a/src/main/java/org/apache/sling/resourceresolver/impl/mapping/AliasHandler.java
b/src/main/java/org/apache/sling/resourceresolver/impl/mapping/AliasHandler.java
index fb2efff0..c6106976 100644
---
a/src/main/java/org/apache/sling/resourceresolver/impl/mapping/AliasHandler.java
+++
b/src/main/java/org/apache/sling/resourceresolver/impl/mapping/AliasHandler.java
@@ -462,34 +462,26 @@ class AliasHandler {
@Nullable List<String> conflictingAliases,
@Nullable List<String> invalidAliases) {
- // resource containing the alias
+ // resource containing the alias (i.e., the parent of a jcr:content
node, otherwise itself)
Resource containingResource = getResourceToBeAliased(resource);
if (containingResource == null) {
log.warn("containingResource is null for alias on {}, skipping.",
resource.getPath());
return false;
} else {
- Resource parent = containingResource.getParent();
-
- if (parent == null) {
- log.warn(
- "{} is null for alias on {}, skipping.",
- containingResource == resource ? "parent" :
"grandparent",
- resource.getPath());
+ // we read the aliases from the resource given in the method call
parameters
+ String[] aliasArray =
resource.getValueMap().get(ResourceResolverImpl.PROP_ALIAS, String[].class);
+ if (aliasArray == null) {
return false;
} else {
- String[] aliasArray =
resource.getValueMap().get(ResourceResolverImpl.PROP_ALIAS, String[].class);
- if (aliasArray == null) {
- return false;
- } else {
- return loadAliasFromArray(
- aliasArray,
- map,
- conflictingAliases,
- invalidAliases,
- containingResource.getName(),
- parent.getPath());
- }
+ // but apply them to the containing resource
+ return loadAliasFromArray(
+ aliasArray,
+ map,
+ conflictingAliases,
+ invalidAliases,
+ containingResource.getName(),
+ ResourceUtil.getParent(containingResource.getPath()));
}
}
}