You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2023/06/23 14:20:29 UTC

[commons-jxpath] 01/02: ClassLoaderUtil.toCanonicalName() now calls Objects.requireNonNull() instead of throwing a RuntimeException

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

commit 28b01872c8c092dee304c3588786338e3e4bdb9a
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Fri Jun 23 10:02:20 2023 -0400

    ClassLoaderUtil.toCanonicalName() now calls Objects.requireNonNull()
    instead of throwing a RuntimeException
    
    Also make the exception message less Engligh-centric
---
 src/changes/changes.xml                                           | 3 +++
 src/main/java/org/apache/commons/jxpath/util/ClassLoaderUtil.java | 7 +++----
 2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 6f07cb8..9d6560d 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -92,6 +92,9 @@ The <action> type attribute can be add,update,fix,remove.
       <action dev="ggregory" type="fix" due-to="Gary Gregory">
         ValueUtils.setValue() now throws IllegalArgumentException instead of RuntimeException.
       </action>
+      <action dev="ggregory" type="fix" due-to="Gary Gregory">
+        ClassLoaderUtil.toCanonicalName() now calls Objects.requireNonNull() instead of throwing a RuntimeException.
+      </action>
       <!-- ADD -->
       <action issue="JXPATH-123" dev="mbenson" type="add">
         XPath function "ends-with" is not implemented (although "starts-with" is).
diff --git a/src/main/java/org/apache/commons/jxpath/util/ClassLoaderUtil.java b/src/main/java/org/apache/commons/jxpath/util/ClassLoaderUtil.java
index 1994b53..eb6eabc 100644
--- a/src/main/java/org/apache/commons/jxpath/util/ClassLoaderUtil.java
+++ b/src/main/java/org/apache/commons/jxpath/util/ClassLoaderUtil.java
@@ -18,6 +18,7 @@ package org.apache.commons.jxpath.util;
 
 import java.util.HashMap;
 import java.util.Map;
+import java.util.Objects;
 
 /**
  * Port of class loading methods from <code>org.apache.commons.lang3.ClassUtils</code> from
@@ -145,10 +146,8 @@ public class ClassLoaderUtil {
      * @return the converted name
      */
     private static String toCanonicalName(String className) {
-        if (className == null) {
-            throw new RuntimeException("Argument className was null.");
-        }
-        else if (className.endsWith("[]")) {
+        Objects.requireNonNull(className, "className");
+        if (className.endsWith("[]")) {
             final StringBuilder classNameBuffer = new StringBuilder();
             while (className.endsWith("[]")) {
                 className = className.substring(0, className.length() - 2);