diff --git a/source/java/org/alfresco/repo/jscript/ScriptNode.java b/source/java/org/alfresco/repo/jscript/ScriptNode.java index 623767e2ad..5d8fd93605 100644 --- a/source/java/org/alfresco/repo/jscript/ScriptNode.java +++ b/source/java/org/alfresco/repo/jscript/ScriptNode.java @@ -478,11 +478,19 @@ public class ScriptNode implements Scopeable, NamespacePrefixResolverProvider * childByNamePath returns the Node at the specified 'cm:name' based Path walking the children of this Node. * So a valid call might be: * mynode.childByNamePath("/QA/Testing/Docs"); - * - * @return The ScriptNode or null if the node is not found. + * + * @param path the relative path of the descendant node to find e.g. {@code "/QA/Testing/Docs"} + * @return The ScriptNode or {@code null} if the node is not found. + * {@code null} if the specified path is {@code ""}. + * @throws NullPointerException if the provided path is {@code null}. */ public ScriptNode childByNamePath(String path) { + // Ensure that paths that do not represent descendants are not needlessly tokenised. See ALF-20896. + if (path == null) { throw new NullPointerException("Illegal null path"); } + else if (path.isEmpty()) { return null; } + + // We have a path worth looking at... ScriptNode child = null; if (this.services.getDictionaryService().isSubClass(getQNameType(), ContentModel.TYPE_FOLDER))