Skip to content

Commit 0a83037

Browse files
authored
SLING-12758: remove redundant check for absolute path in alias (#171)
1 parent 95f39b9 commit 0a83037

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverImpl.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -928,20 +928,21 @@ private Resource getChildInternal(final Resource parent, final String childName)
928928
// we do not have a child with the exact name, so we look for
929929
// a child, whose alias matches the childName
930930
if (factory.getMapEntries().isOptimizeAliasResolutionEnabled()) {
931-
logger.debug("getChildInternal: Optimize Alias Resolution is Enabled");
932-
// optimization made in SLING-2521
931+
final String parentPath = parent.getPath();
932+
logger.debug(
933+
"getChildInternal: Optimize Alias Resolution is Enabled, looking up {} in {}",
934+
childName,
935+
parentPath);
936+
937+
// optimized alias resolution: aliases are cached by MapEntries
933938
final Optional<String> aliasedResourceName =
934-
factory.getMapEntries().getAliasMap(parent.getPath()).entrySet().stream()
939+
factory.getMapEntries().getAliasMap(parentPath).entrySet().stream()
935940
.filter(e -> e.getValue().contains(childName))
936941
.findFirst()
937942
.map(Map.Entry::getKey);
938943
if (aliasedResourceName.isPresent()) {
939-
final String aliasPath;
940-
if (aliasedResourceName.get().startsWith("/")) {
941-
aliasPath = aliasedResourceName.get();
942-
} else {
943-
aliasPath = parent.getPath() + '/' + aliasedResourceName.get();
944-
}
944+
// we know that MapEntries already has checked for valid aliases
945+
final String aliasPath = parentPath + '/' + aliasedResourceName.get();
945946
final Resource aliasedChild =
946947
getAbsoluteResourceInternal(parent, ResourceUtil.normalize(aliasPath), EMPTY_PARAMETERS, true);
947948
logger.debug("getChildInternal: Found Resource {} with alias {} to use", aliasedChild, childName);

0 commit comments

Comments
 (0)