From ac4213cd9cd335ca4d87ef5c7dca490294420c8e Mon Sep 17 00:00:00 2001 From: Will Abson Date: Wed, 3 Sep 2014 18:07:02 +0000 Subject: [PATCH] Merged HEAD-BUG-FIX (5.0/Cloud) to HEAD (5.0/Cloud) 80871: Fix for ALF-20896. ScriptNode.childByPath should return null for no child. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@83123 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../java/org/alfresco/repo/jscript/ScriptNode.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) 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))