Ver código fonte

fix for classcast exception while evaluating SMTP send errors

Jason Rivard 2 anos atrás
pai
commit
7d31310bf4

+ 7 - 11
lib-util/src/main/java/password/pwm/util/java/JavaHelper.java

@@ -339,30 +339,26 @@ public final class JavaHelper
         return returnValue;
         return returnValue;
     }
     }
 
 
-    public static <T> Optional<T> extractNestedExceptionType( final Exception inputException, final Class<T> exceptionType )
+    public static <T> Optional<T> extractNestedExceptionType( final Throwable inputException, final Class<T> exceptionType )
     {
     {
         if ( inputException == null )
         if ( inputException == null )
         {
         {
             return Optional.empty();
             return Optional.empty();
         }
         }
 
 
-        if ( inputException.getClass().isAssignableFrom( exceptionType ) )
+        if ( inputException.getClass().isInstance( exceptionType ) )
         {
         {
             return Optional.of( ( T ) inputException );
             return Optional.of( ( T ) inputException );
         }
         }
 
 
-        Throwable nextException = inputException.getCause();
-        while ( nextException != null )
-        {
-            if ( nextException.getClass().isAssignableFrom( exceptionType ) )
-            {
-                return Optional.of( ( T ) inputException );
-            }
+        final Throwable nextException = inputException.getCause();
 
 
-            nextException = nextException.getCause();
+        if ( nextException == null )
+        {
+            return Optional.empty();
         }
         }
 
 
-        return Optional.empty();
+        return extractNestedExceptionType( nextException, exceptionType );
     }
     }
 
 
     public static Map<String, String> propertiesToStringMap( final Properties properties )
     public static Map<String, String> propertiesToStringMap( final Properties properties )