Index: jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/util/Text.java =================================================================== --- jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/util/Text.java (revision 682477) +++ jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/util/Text.java (working copy) @@ -509,26 +509,35 @@ } /** - * Returns the name part of the path + * Returns the name part of the path. If the given path is already a name + * (i.e. contains no slashes) it is returned. * * @param path the path - * @return the name part + * @return the name part or null if path is null. */ public static String getName(String path) { - int pos = path.lastIndexOf('/'); - return pos >= 0 ? path.substring(pos + 1) : ""; + if (path == null) { + return null; + } else { + return path.substring(path.lastIndexOf('/')); + } } /** - * Returns the name part of the path, delimited by the given delim + * Returns the name part of the path, delimited by the given delim. + * If the given path is already a name (i.e. contains no delim + * characters) it is returned. * * @param path the path * @param delim the delimiter - * @return the name part + * @return the name part or null if path is null. */ public static String getName(String path, char delim) { - int pos = path.lastIndexOf(delim); - return pos >= 0 ? path.substring(pos + 1) : ""; + if (path == null) { + return null; + } else { + return path.substring(path.lastIndexOf(delim)); + } } /** @@ -538,7 +547,7 @@ * @see #getName(String) */ public static String getName(String path, boolean ignoreTrailingSlash) { - if (ignoreTrailingSlash && path.endsWith("/") && path.length() > 1) { + if (ignoreTrailingSlash && path != null && path.endsWith("/") && path.length() > 1) { path = path.substring(0, path.length()-1); } return getName(path);