This is an automated email from the ASF dual-hosted git repository. ggregory pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-jxpath.git
The following commit(s) were added to refs/heads/master by this push: new f8de21b Fix possible NPE in PackageFunctions.getFunction(String, String, Object[]). f8de21b is described below commit f8de21bd78922b6358cc8187e57db843f5dedf8c Author: Gary Gregory <garydgreg...@gmail.com> AuthorDate: Tue Oct 18 14:03:42 2022 -0400 Fix possible NPE in PackageFunctions.getFunction(String, String, Object[]). Fix PMD issues --- .../apache/commons/jxpath/PackageFunctions.java | 36 ++++++++++++---------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/src/main/java/org/apache/commons/jxpath/PackageFunctions.java b/src/main/java/org/apache/commons/jxpath/PackageFunctions.java index 2059587..3a2e4a1 100644 --- a/src/main/java/org/apache/commons/jxpath/PackageFunctions.java +++ b/src/main/java/org/apache/commons/jxpath/PackageFunctions.java @@ -21,6 +21,7 @@ import java.lang.reflect.Method; import java.util.Collection; import java.util.Collections; import java.util.Iterator; +import java.util.Objects; import java.util.Set; import org.apache.commons.jxpath.functions.ConstructorFunction; @@ -66,16 +67,16 @@ import org.apache.commons.jxpath.util.TypeUtils; * </p> */ public class PackageFunctions implements Functions { - private String classPrefix; - private String namespace; - private static final Object[] EMPTY_ARRAY = new Object[0]; + private final String classPrefix; + private final String namespace; + private static final Object[] EMPTY_ARRAY = {}; /** * Create a new PackageFunctions. * @param classPrefix class prefix * @param namespace namespace String */ - public PackageFunctions(String classPrefix, String namespace) { + public PackageFunctions(final String classPrefix, final String namespace) { this.classPrefix = classPrefix; this.namespace = namespace; } @@ -84,6 +85,7 @@ public class PackageFunctions implements Functions { * Returns the namespace specified in the constructor * @return (singleton) namespace Set */ + @Override public Set getUsedNamespaces() { return Collections.singleton(namespace); } @@ -109,12 +111,12 @@ public class PackageFunctions implements Functions { * @return a MethodFunction, a ConstructorFunction or null if no function * is found */ + @Override public Function getFunction( - String namespace, - String name, + final String namespace, + final String name, Object[] parameters) { - if ((namespace == null && this.namespace != null) //NOPMD - || (namespace != null && !namespace.equals(this.namespace))) { + if (!Objects.equals(this.namespace, namespace)) { return null; } @@ -148,7 +150,7 @@ public class PackageFunctions implements Functions { } if (target instanceof Collection) { - Iterator iter = ((Collection) target).iterator(); + final Iterator iter = ((Collection) target).iterator(); if (iter.hasNext()) { target = iter.next(); if (target instanceof Pointer) { @@ -161,7 +163,7 @@ public class PackageFunctions implements Functions { } } if (target != null) { - Method method = + final Method method = MethodLookupUtils.lookupMethod( target.getClass(), name, @@ -172,20 +174,20 @@ public class PackageFunctions implements Functions { } } - String fullName = classPrefix + name; - int inx = fullName.lastIndexOf('.'); + final String fullName = classPrefix + name; + final int inx = fullName.lastIndexOf('.'); if (inx == -1) { return null; } - String className = fullName.substring(0, inx); - String methodName = fullName.substring(inx + 1); + final String className = fullName.substring(0, inx); + final String methodName = fullName.substring(inx + 1); Class functionClass; try { functionClass = ClassLoaderUtil.getClass(className, true); } - catch (ClassNotFoundException ex) { + catch (final ClassNotFoundException ex) { throw new JXPathException( "Cannot invoke extension function " + (namespace != null ? namespace + ":" + name : name), @@ -193,14 +195,14 @@ public class PackageFunctions implements Functions { } if (methodName.equals("new")) { - Constructor constructor = + final Constructor constructor = MethodLookupUtils.lookupConstructor(functionClass, parameters); if (constructor != null) { return new ConstructorFunction(constructor); } } else { - Method method = + final Method method = MethodLookupUtils.lookupStaticMethod( functionClass, methodName,