This is an automated email from the ASF dual-hosted git repository.

michaelo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-resolver.git


The following commit(s) were added to refs/heads/master by this push:
     new bf96c71  Check if value is really non-null String before attempt to 
parse it. Checking type and nullness beforehand can help avoid exceptions (like 
NullPointerException and ClassCastException) in almost all cases. Usage of 
exceptional flow affects performance. Also catching general Exception is 
usually considered as bad smell.
bf96c71 is described below

commit bf96c7108ea6f6d39bfcdc64acfa491f5f71460e
Author: Andrey Turbanov <[email protected]>
AuthorDate: Tue Sep 14 16:35:29 2021 +0300

    Check if value is really non-null String before attempt to parse it.
    Checking type and nullness beforehand can help avoid exceptions (like 
NullPointerException and ClassCastException) in almost all cases.
    Usage of exceptional flow affects performance.
    Also catching general Exception is usually considered as bad smell.
---
 .../java/org/eclipse/aether/util/ConfigUtils.java  | 51 ++++++++++++----------
 1 file changed, 27 insertions(+), 24 deletions(-)

diff --git 
a/maven-resolver-util/src/main/java/org/eclipse/aether/util/ConfigUtils.java 
b/maven-resolver-util/src/main/java/org/eclipse/aether/util/ConfigUtils.java
index b55ad57..ca00202 100644
--- a/maven-resolver-util/src/main/java/org/eclipse/aether/util/ConfigUtils.java
+++ b/maven-resolver-util/src/main/java/org/eclipse/aether/util/ConfigUtils.java
@@ -139,14 +139,15 @@ public final class ConfigUtils
             {
                 return ( (Number) value ).intValue();
             }
-
-            try
-            {
-                return Integer.parseInt( (String) value );
-            }
-            catch ( Exception e )
-            {
-                // try next key
+            else if ( value instanceof String ) {
+                try
+                {
+                    return Integer.parseInt( (String) value );
+                }
+                catch ( NumberFormatException e )
+                {
+                    // try next key
+                }
             }
         }
 
@@ -187,14 +188,15 @@ public final class ConfigUtils
             {
                 return ( (Number) value ).longValue();
             }
-
-            try
-            {
-                return Long.parseLong( (String) value );
-            }
-            catch ( Exception e )
-            {
-                // try next key
+            else if ( value instanceof String ) {
+                try
+                {
+                    return Long.parseLong( (String) value );
+                }
+                catch ( NumberFormatException e )
+                {
+                    // try next key
+                }
             }
         }
 
@@ -235,14 +237,15 @@ public final class ConfigUtils
             {
                 return ( (Number) value ).floatValue();
             }
-
-            try
-            {
-                return Float.parseFloat( (String) value );
-            }
-            catch ( Exception e )
-            {
-                // try next key
+            else if ( value instanceof String ) {
+                try
+                {
+                    return Float.parseFloat( (String) value );
+                }
+                catch ( NumberFormatException e )
+                {
+                    // try next key
+                }
             }
         }
 

Reply via email to