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

doebele pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/empire-db.git


The following commit(s) were added to refs/heads/master by this push:
     new fed61d30 EMPIREDB-456 New BeanMethodInvokeException for 
ReflectiveOperations on methods
fed61d30 is described below

commit fed61d30f29f67d77f0134e546f906cdf07565b4
Author: Rainer Döbele <[email protected]>
AuthorDate: Mon Mar 24 10:36:13 2025 +0100

    EMPIREDB-456
    New BeanMethodInvokeException for ReflectiveOperations on methods
---
 .../java/org/apache/empire/commons/ClassUtils.java |  16 +--
 .../empire/db/list/DBRecordListFactoryImpl.java    |   1 -
 ...tantiationException.java => BeanException.java} | 156 ++++++++++++---------
 .../exceptions/BeanInstantiationException.java     |  19 +--
 ...ception.java => BeanMethodInvokeException.java} |  95 +++++--------
 .../exceptions/BeanPropertyGetException.java       |  24 +---
 .../exceptions/BeanPropertySetException.java       |  24 +---
 .../apache/empire/exceptions/EmpireException.java  |  18 ---
 .../empire/exceptions/NotSupportedException.java   |   7 +-
 9 files changed, 141 insertions(+), 219 deletions(-)

diff --git a/empire-db/src/main/java/org/apache/empire/commons/ClassUtils.java 
b/empire-db/src/main/java/org/apache/empire/commons/ClassUtils.java
index 768ca61c..83dc464a 100644
--- a/empire-db/src/main/java/org/apache/empire/commons/ClassUtils.java
+++ b/empire-db/src/main/java/org/apache/empire/commons/ClassUtils.java
@@ -33,10 +33,10 @@ import java.net.URISyntaxException;
 
 import org.apache.commons.beanutils.ConstructorUtils;
 import org.apache.empire.exceptions.BeanInstantiationException;
+import org.apache.empire.exceptions.BeanMethodInvokeException;
 import org.apache.empire.exceptions.InternalException;
 import org.apache.empire.exceptions.InvalidArgumentException;
 import org.apache.empire.exceptions.NotImplementedException;
-import org.apache.empire.exceptions.NotSupportedException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -287,7 +287,7 @@ public final class ClassUtils
         }
         catch (IllegalAccessException e)
         {   // Invalid Method definition   
-            throw new NotSupportedException(object, property, e);
+            throw new BeanMethodInvokeException(object, property, e);
         }
         finally {
             // restore accessible
@@ -589,11 +589,11 @@ public final class ClassUtils
         }
         catch (IllegalAccessException | InvocationTargetException e)
         {   // ReflectiveOperationException   
-            throw new NotSupportedException(object, methodName, e);
+            throw new BeanMethodInvokeException(object, methodName, e);
         }
         catch (SecurityException | IllegalArgumentException e)
         {   // RuntimeException   
-            throw new NotSupportedException(object, methodName, e);
+            throw new BeanMethodInvokeException(object, methodName, e);
         }
         finally {
             // restore accessible
@@ -687,11 +687,11 @@ public final class ClassUtils
         }
         catch (IllegalAccessException | InvocationTargetException e)
         {   // ReflectiveOperationException 
-            throw new NotSupportedException(object, method.getName(), e); 
+            throw new BeanMethodInvokeException(object, method.getName(), e); 
         }
         catch (SecurityException | IllegalArgumentException e)
         {   // RuntimeException
-            throw new NotSupportedException(object, method.getName(), e); 
+            throw new BeanMethodInvokeException(object, method.getName(), e); 
         } 
     }
 
@@ -715,11 +715,11 @@ public final class ClassUtils
         }
         catch (IllegalAccessException | InvocationTargetException e)
         {   // ReflectiveOperationException 
-            throw new NotSupportedException(object, method.getName(), e); 
+            throw new BeanMethodInvokeException(object, method.getName(), e); 
         }
         catch (SecurityException | IllegalArgumentException e)
         {   // RuntimeException
-            throw new NotSupportedException(object, method.getName(), e); 
+            throw new BeanMethodInvokeException(object, method.getName(), e); 
         } 
     }
     
diff --git 
a/empire-db/src/main/java/org/apache/empire/db/list/DBRecordListFactoryImpl.java
 
b/empire-db/src/main/java/org/apache/empire/db/list/DBRecordListFactoryImpl.java
index fec66a10..1009a1e4 100644
--- 
a/empire-db/src/main/java/org/apache/empire/db/list/DBRecordListFactoryImpl.java
+++ 
b/empire-db/src/main/java/org/apache/empire/db/list/DBRecordListFactoryImpl.java
@@ -34,7 +34,6 @@ import org.apache.empire.db.DBRecordBean;
 import org.apache.empire.db.DBRecordData;
 import org.apache.empire.db.DBRowSet;
 import org.apache.empire.exceptions.BeanInstantiationException;
-import org.apache.empire.exceptions.InternalException;
 import org.apache.empire.exceptions.InvalidPropertyException;
 import org.apache.empire.exceptions.UnsupportedTypeException;
 import org.slf4j.Logger;
diff --git 
a/empire-db/src/main/java/org/apache/empire/exceptions/BeanInstantiationException.java
 b/empire-db/src/main/java/org/apache/empire/exceptions/BeanException.java
similarity index 51%
copy from 
empire-db/src/main/java/org/apache/empire/exceptions/BeanInstantiationException.java
copy to empire-db/src/main/java/org/apache/empire/exceptions/BeanException.java
index d54b81e2..c66cd1ad 100644
--- 
a/empire-db/src/main/java/org/apache/empire/exceptions/BeanInstantiationException.java
+++ b/empire-db/src/main/java/org/apache/empire/exceptions/BeanException.java
@@ -1,69 +1,87 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *  http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.empire.exceptions;
-
-import java.lang.reflect.Constructor;
-
-import org.apache.empire.commons.ErrorType;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class BeanInstantiationException extends EmpireException
-{
-    private static final long serialVersionUID = 1L;
-
-    // Logger
-    private static final Logger log = 
LoggerFactory.getLogger(BeanInstantiationException.class);
-    
-    public static final ErrorType errorType = new 
ErrorType("error.beanInstantiationFailed", "Unable create an instance of type 
{0}.");
-    
-    public BeanInstantiationException(Class<?> clazz, 
ReflectiveOperationException e)
-    {
-        super(errorType, new String[] { clazz.getName() }, getCause(e));
-    }
-    
-    public BeanInstantiationException(Class<?> clazz, RuntimeException e)
-    {
-        super(errorType, new String[] { clazz.getName() }, e);
-    }
-    
-    public BeanInstantiationException(Constructor<?> c, 
ReflectiveOperationException e)
-    {
-        this(c.getDeclaringClass(), e);
-    }
-    
-    public BeanInstantiationException(Constructor<?> c, RuntimeException e)
-    {
-        this(c.getDeclaringClass(), e);
-    }
-    
-    /**
-     * log the error
-     */
-    @Override
-    protected void log()
-    {
-       if ( log.isErrorEnabled() )
-            log.error(getMessage());
-       else
-           super.log();
-    }
-    
-    
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.empire.exceptions;
+
+import org.apache.empire.commons.ErrorType;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * BeanException
+ * Base class for bean related exceptions
+ * @author doebele
+ */
+public abstract class BeanException extends EmpireException
+{
+    private static final long serialVersionUID = 1L;
+    // Logger
+    private static final Logger log = 
LoggerFactory.getLogger(BeanException.class);
+    
+    /**
+     * Returns the root cause of a ReflectiveOperationException such as 
InvocationTargetException
+     * @param e the ReflectiveOperationException
+     * @return the causing exception
+     */
+    protected static Exception getCause(ReflectiveOperationException e)
+    {
+        Throwable cause = e.getCause();
+        /*
+        if (cause instanceof EmpireException)
+            return ((EmpireException)cause);
+        */
+        if (cause instanceof Exception)
+            return (Exception)cause;
+        // wrap    
+        return e;
+    }
+    
+    protected static String getTypeName(Object object)
+    {
+        if (object instanceof Class<?>)
+            return ((Class<?>)object).getName();
+        if (object!=null)
+            return object.getClass().getName();
+        // null
+        return "{unknown}";
+    }
+
+    /**
+     * Constructor
+     * @param errType the error type
+     * @param params the error params
+     * @param cause the causing exception
+     */
+    protected BeanException(ErrorType errType, String[] params, Throwable 
cause)
+    {
+        super(errType, params, cause);
+    }
+    
+    /**
+     * log the error
+     */
+    @Override
+    protected void log()
+    {
+       if ( log.isErrorEnabled() )
+            log.error(getMessage());
+       else
+           super.log();
+    }
+    
+}
diff --git 
a/empire-db/src/main/java/org/apache/empire/exceptions/BeanInstantiationException.java
 
b/empire-db/src/main/java/org/apache/empire/exceptions/BeanInstantiationException.java
index d54b81e2..9dccf33a 100644
--- 
a/empire-db/src/main/java/org/apache/empire/exceptions/BeanInstantiationException.java
+++ 
b/empire-db/src/main/java/org/apache/empire/exceptions/BeanInstantiationException.java
@@ -21,15 +21,10 @@ package org.apache.empire.exceptions;
 import java.lang.reflect.Constructor;
 
 import org.apache.empire.commons.ErrorType;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
-public class BeanInstantiationException extends EmpireException
+public class BeanInstantiationException extends BeanException
 {
     private static final long serialVersionUID = 1L;
-
-    // Logger
-    private static final Logger log = 
LoggerFactory.getLogger(BeanInstantiationException.class);
     
     public static final ErrorType errorType = new 
ErrorType("error.beanInstantiationFailed", "Unable create an instance of type 
{0}.");
     
@@ -53,17 +48,5 @@ public class BeanInstantiationException extends 
EmpireException
         this(c.getDeclaringClass(), e);
     }
     
-    /**
-     * log the error
-     */
-    @Override
-    protected void log()
-    {
-       if ( log.isErrorEnabled() )
-            log.error(getMessage());
-       else
-           super.log();
-    }
-    
     
 }
diff --git 
a/empire-db/src/main/java/org/apache/empire/exceptions/BeanPropertySetException.java
 
b/empire-db/src/main/java/org/apache/empire/exceptions/BeanMethodInvokeException.java
similarity index 51%
copy from 
empire-db/src/main/java/org/apache/empire/exceptions/BeanPropertySetException.java
copy to 
empire-db/src/main/java/org/apache/empire/exceptions/BeanMethodInvokeException.java
index 0613001a..29164edb 100644
--- 
a/empire-db/src/main/java/org/apache/empire/exceptions/BeanPropertySetException.java
+++ 
b/empire-db/src/main/java/org/apache/empire/exceptions/BeanMethodInvokeException.java
@@ -1,57 +1,38 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *  http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.empire.exceptions;
-
-import org.apache.empire.commons.ErrorType;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class BeanPropertySetException extends EmpireException
-{
-    private static final long serialVersionUID = 1L;
-
-    // Logger
-    private static final Logger log = 
LoggerFactory.getLogger(BeanPropertySetException.class);
-    
-    public static final ErrorType errorType = new 
ErrorType("error.propertySetError", "The property {0} cannot be set on type 
{1}.");
-
-    public BeanPropertySetException(Object bean, String property, 
ReflectiveOperationException e)
-    {
-        super(errorType, new String[] { property, (bean!=null ? 
bean.getClass().getName() : "{unknown}") }, getCause(e));
-    }
-    
-    public BeanPropertySetException(Object bean, String property, 
RuntimeException e)
-    {
-        super(errorType, new String[] { property, (bean!=null ? 
bean.getClass().getName() : "{unknown}") }, e);
-    }
-    
-    /**
-     * log the error
-     */
-    @Override
-    protected void log()
-    {
-       if ( log.isErrorEnabled() )
-            log.error(getMessage());
-       else
-           super.log();
-    }
-    
-    
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.empire.exceptions;
+
+import org.apache.empire.commons.ErrorType;
+
+public class BeanMethodInvokeException extends BeanException
+{
+    private static final long serialVersionUID = 1L;
+    
+    public static final ErrorType errorType = new 
ErrorType("error.methodInvokeError", "The method {0} failed on object of type 
{1}");
+
+    public BeanMethodInvokeException(Object bean, String method, 
ReflectiveOperationException e)
+    {
+        super(errorType, new String[] { method, getTypeName(bean) }, 
getCause(e));
+    }
+    
+    public BeanMethodInvokeException(Object bean, String method, 
RuntimeException e)
+    {
+        super(errorType, new String[] { method, getTypeName(bean) }, e);
+    }
+}
diff --git 
a/empire-db/src/main/java/org/apache/empire/exceptions/BeanPropertyGetException.java
 
b/empire-db/src/main/java/org/apache/empire/exceptions/BeanPropertyGetException.java
index e2e83b5c..c664629c 100644
--- 
a/empire-db/src/main/java/org/apache/empire/exceptions/BeanPropertyGetException.java
+++ 
b/empire-db/src/main/java/org/apache/empire/exceptions/BeanPropertyGetException.java
@@ -19,39 +19,21 @@
 package org.apache.empire.exceptions;
 
 import org.apache.empire.commons.ErrorType;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
-public class BeanPropertyGetException extends EmpireException
+public class BeanPropertyGetException extends BeanException
 {
     private static final long serialVersionUID = 1L;
-
-    // Logger
-    private static final Logger log = 
LoggerFactory.getLogger(BeanPropertyGetException.class);
     
     public static final ErrorType errorType = new 
ErrorType("error.propertyGetError", "Unable to get the property {0} from type 
{1}.");
     
     public BeanPropertyGetException(Object bean, String property, 
ReflectiveOperationException e)
     {
-        super(errorType, new String[] { property, (bean!=null ? 
bean.getClass().getName() : "{unknown}") }, getCause(e));
+        super(errorType, new String[] { property, getTypeName(bean) }, 
getCause(e));
     }
     
     public BeanPropertyGetException(Object bean, String property, 
RuntimeException e)
     {
-        super(errorType, new String[] { property, (bean!=null ? 
bean.getClass().getName() : "{unknown}") }, e);
+        super(errorType, new String[] { property, getTypeName(bean) }, e);
     }
     
-    /**
-     * log the error
-     */
-    @Override
-    protected void log()
-    {
-       if ( log.isErrorEnabled() )
-            log.error(getMessage());
-       else
-           super.log();
-    }
-    
-    
 }
diff --git 
a/empire-db/src/main/java/org/apache/empire/exceptions/BeanPropertySetException.java
 
b/empire-db/src/main/java/org/apache/empire/exceptions/BeanPropertySetException.java
index 0613001a..47f28a8d 100644
--- 
a/empire-db/src/main/java/org/apache/empire/exceptions/BeanPropertySetException.java
+++ 
b/empire-db/src/main/java/org/apache/empire/exceptions/BeanPropertySetException.java
@@ -19,39 +19,21 @@
 package org.apache.empire.exceptions;
 
 import org.apache.empire.commons.ErrorType;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
-public class BeanPropertySetException extends EmpireException
+public class BeanPropertySetException extends BeanException
 {
     private static final long serialVersionUID = 1L;
-
-    // Logger
-    private static final Logger log = 
LoggerFactory.getLogger(BeanPropertySetException.class);
     
     public static final ErrorType errorType = new 
ErrorType("error.propertySetError", "The property {0} cannot be set on type 
{1}.");
 
     public BeanPropertySetException(Object bean, String property, 
ReflectiveOperationException e)
     {
-        super(errorType, new String[] { property, (bean!=null ? 
bean.getClass().getName() : "{unknown}") }, getCause(e));
+        super(errorType, new String[] { property, getTypeName(bean) }, 
getCause(e));
     }
     
     public BeanPropertySetException(Object bean, String property, 
RuntimeException e)
     {
-        super(errorType, new String[] { property, (bean!=null ? 
bean.getClass().getName() : "{unknown}") }, e);
+        super(errorType, new String[] { property, getTypeName(bean) }, e);
     }
     
-    /**
-     * log the error
-     */
-    @Override
-    protected void log()
-    {
-       if ( log.isErrorEnabled() )
-            log.error(getMessage());
-       else
-           super.log();
-    }
-    
-    
 }
diff --git 
a/empire-db/src/main/java/org/apache/empire/exceptions/EmpireException.java 
b/empire-db/src/main/java/org/apache/empire/exceptions/EmpireException.java
index 5877290b..9ad3aee7 100644
--- a/empire-db/src/main/java/org/apache/empire/exceptions/EmpireException.java
+++ b/empire-db/src/main/java/org/apache/empire/exceptions/EmpireException.java
@@ -123,24 +123,6 @@ public class EmpireException extends RuntimeException
         return messageFormatter.format(errType, pattern, params);
     }
     
-    /**
-     * Returns the root cause of a ReflectiveOperationException such as 
InvocationTargetException
-     * @param e the ReflectiveOperationException
-     * @return the causing exception
-     */
-    protected static Exception getCause(ReflectiveOperationException e)
-    {
-        Throwable cause = e.getCause();
-        /*
-        if (cause instanceof EmpireException)
-            return ((EmpireException)cause);
-        */
-        if (cause instanceof Exception)
-            return (Exception)cause;
-        // wrap    
-        return e;
-    }
-    
     private final ErrorType errorType;
     private final String[]  errorParams;
     // private final String errorSourceClassname;
diff --git 
a/empire-db/src/main/java/org/apache/empire/exceptions/NotSupportedException.java
 
b/empire-db/src/main/java/org/apache/empire/exceptions/NotSupportedException.java
index 12452508..dc8413d5 100644
--- 
a/empire-db/src/main/java/org/apache/empire/exceptions/NotSupportedException.java
+++ 
b/empire-db/src/main/java/org/apache/empire/exceptions/NotSupportedException.java
@@ -38,12 +38,7 @@ public class NotSupportedException extends EmpireException
         return "-";
     }
     
-    public NotSupportedException(Object object, String operationName, 
ReflectiveOperationException e)
-    {
-        super(errorType, new String[] { operationName, typeFromObject(object) 
}, getCause(e));
-    }
-    
-    public NotSupportedException(Object object, String operationName, 
RuntimeException e)
+    public NotSupportedException(Object object, String operationName, 
Exception e)
     {
         super(errorType, new String[] { operationName, typeFromObject(object) 
}, e);
     }

Reply via email to