[seam-commits] Seam SVN: r12812 - modules/security/trunk/impl/src/main/java/org/jboss/seam/security/util.

seam-commits at lists.jboss.org seam-commits at lists.jboss.org
Wed May 26 10:29:30 EDT 2010


Author: shane.bryzak at jboss.com
Date: 2010-05-26 10:29:29 -0400 (Wed, 26 May 2010)
New Revision: 12812

Modified:
   modules/security/trunk/impl/src/main/java/org/jboss/seam/security/util/AnnotatedBeanProperty.java
Log:
separate catch blocks for each exception


Modified: modules/security/trunk/impl/src/main/java/org/jboss/seam/security/util/AnnotatedBeanProperty.java
===================================================================
--- modules/security/trunk/impl/src/main/java/org/jboss/seam/security/util/AnnotatedBeanProperty.java	2010-05-26 14:21:29 UTC (rev 12811)
+++ modules/security/trunk/impl/src/main/java/org/jboss/seam/security/util/AnnotatedBeanProperty.java	2010-05-26 14:29:29 UTC (rev 12812)
@@ -275,35 +275,38 @@
       {
          return method.invoke(obj, args);
       }
-      catch (Throwable ex)
+      catch (IllegalAccessException ex)
       {
-         StringBuilder message = new StringBuilder(String.format(
-               "Exception invoking method [%s] on object [%s], using arguments [",
-               method.getName(), obj));
-         if (args != null) for (int i = 0; i < args.length; i++) message.append((i > 0 ? "," : "") + args[i]);
-         message.append("]");
-         
-         if (ex instanceof InvocationTargetException) ex = (Exception) ex.getCause();
-         
-         if (ex instanceof IllegalAccessException ||
-               ex instanceof IllegalArgumentException ||
-               ex instanceof InvocationTargetException ||
-               ex instanceof NullPointerException ||
-               ex instanceof ExceptionInInitializerError) 
-         {
-            throw new RuntimeException(message.toString(), ex);
-         }
-         else if (ex instanceof RuntimeException)
-         {
-            throw (RuntimeException) ex;
-         }
-         else
-         {
-            throw new RuntimeException(ex);
-         }
+         throw new RuntimeException(buildInvokeMethodErrorMessage(method, obj, args), ex);
       }
+      catch (IllegalArgumentException ex)
+      {
+         throw new RuntimeException(buildInvokeMethodErrorMessage(method, obj, args), ex);
+      }
+      catch (InvocationTargetException ex)
+      {
+         throw new RuntimeException(buildInvokeMethodErrorMessage(method, obj, args), ex);
+      }
+      catch (NullPointerException ex)
+      {
+         throw new RuntimeException(buildInvokeMethodErrorMessage(method, obj, args), ex);
+      }
+      catch (ExceptionInInitializerError e)
+      {
+         throw new RuntimeException(buildInvokeMethodErrorMessage(method, obj, args), ex);
+      }
    }   
    
+   private String buildInvokeMethodErrorMessage(Method method, Object obj, Object... args)
+   {
+      StringBuilder message = new StringBuilder(String.format(
+            "Exception invoking method [%s] on object [%s], using arguments [",
+            method.getName(), obj));
+      if (args != null) for (int i = 0; i < args.length; i++) message.append((i > 0 ? "," : "") + args[i]);
+      message.append("]");
+      return message.toString();
+   }
+   
    private Method getSetterMethod(Class<?> clazz, String name)
    {
       Method[] methods = clazz.getMethods();



More information about the seam-commits mailing list