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 902737e1 EMPIREDB-456 Improved exception handling for 
ReflectiveOperationExceptions
902737e1 is described below

commit 902737e15703c0e4b674fe0e5f3ade79839d2a3d
Author: Rainer Döbele <[email protected]>
AuthorDate: Mon Mar 24 09:58:04 2025 +0100

    EMPIREDB-456
    Improved exception handling for ReflectiveOperationExceptions
---
 .../apache/empire/commons/BeanPropertyUtils.java   | 38 ++++-----
 .../java/org/apache/empire/commons/ClassUtils.java | 93 ++++++++--------------
 .../org/apache/empire/data/list/DataListEntry.java |  2 +-
 .../empire/data/list/DataListFactoryImpl.java      | 20 ++---
 .../main/java/org/apache/empire/db/DBObject.java   |  2 +-
 .../main/java/org/apache/empire/db/DBReader.java   |  7 +-
 .../java/org/apache/empire/db/DBRecordData.java    |  2 +-
 .../empire/db/list/DBBeanListFactoryImpl.java      | 12 ++-
 .../empire/db/list/DBRecordListFactoryImpl.java    | 11 ++-
 .../exceptions/BeanInstantiationException.java     | 21 ++++-
 .../exceptions/BeanPropertyGetException.java       |  9 ++-
 .../exceptions/BeanPropertySetException.java       |  9 ++-
 .../apache/empire/exceptions/EmpireException.java  | 18 +++++
 .../empire/exceptions/InternalException.java       |  2 +-
 .../empire/exceptions/NotSupportedException.java   |  9 ++-
 .../org/apache/empire/xml/XMLConfiguration.java    | 10 ++-
 16 files changed, 137 insertions(+), 128 deletions(-)

diff --git 
a/empire-db/src/main/java/org/apache/empire/commons/BeanPropertyUtils.java 
b/empire-db/src/main/java/org/apache/empire/commons/BeanPropertyUtils.java
index c7dff721..0e929d21 100644
--- a/empire-db/src/main/java/org/apache/empire/commons/BeanPropertyUtils.java
+++ b/empire-db/src/main/java/org/apache/empire/commons/BeanPropertyUtils.java
@@ -146,8 +146,10 @@ public final class BeanPropertyUtils
                     method = propUtils.getReadMethod(pd);
                 }
                 return (method!=null ? 1 : 0);
-            } catch (IllegalAccessException | InvocationTargetException | 
NoSuchMethodException e)
-            {   log.warn("Property access not available for {} on {}", 
property, bean.getClass().getName());
+            } catch (NoSuchMethodException | IllegalAccessException | 
InvocationTargetException e) {
+                // ReflectiveOperationException
+                Throwable cause = (e.getCause()!=null ? e.getCause() : e); 
+                log.warn("Property access failed for {} on {}: {}", property, 
bean.getClass().getName(), cause.getMessage());
                 return 0;
             }
         }
@@ -167,14 +169,9 @@ public final class BeanPropertyUtils
                 PropertyUtilsBean pub = 
BeanUtilsBean.getInstance().getPropertyUtils();
                 return pub.getSimpleProperty(bean, property);
     
-            } catch (IllegalAccessException e)
-            {   log.error(bean.getClass().getName() + ": unable to get 
property '" + property + "'");
-                throw new BeanPropertyGetException(bean, property, e);
-            } catch (InvocationTargetException e)
-            {   log.error(bean.getClass().getName() + ": unable to get 
property '" + property + "'");
-                throw new BeanPropertyGetException(bean, property, e);
-            } catch (NoSuchMethodException e)
-            {   log.warn(bean.getClass().getName() + ": no getter available 
for property '" + property + "'");
+            } catch (NoSuchMethodException | IllegalAccessException | 
InvocationTargetException e) {
+                // ReflectiveOperationException
+                log.error(bean.getClass().getName() + ": unable to get 
property '" + property + "'");
                 throw new BeanPropertyGetException(bean, property, e);
             }
         }
@@ -221,20 +218,13 @@ public final class BeanPropertyUtils
                 else
                     method.invoke(bean, value);
                 return true;
-              // IllegalAccessException
-            } catch (IllegalAccessException e)
-            {   log.error(bean.getClass().getName() + ": unable to set 
property '" + property + "'");
-                throw new BeanPropertySetException(bean, property, e);
-              // InvocationTargetException  
-            } catch (InvocationTargetException e)
-            {   log.error(bean.getClass().getName() + ": unable to set 
property '" + property + "'");
-                throw new BeanPropertySetException(bean, property, e);
-              // NoSuchMethodException   
-            } catch (NoSuchMethodException e)
-            {   log.error(bean.getClass().getName() + ": unable to set 
property '" + property + "'");
-                throw new BeanPropertySetException(bean, property, e);
-            } catch (NullPointerException e)
-            {   log.error(bean.getClass().getName() + ": unable to set 
property '" + property + "'");
+            } catch (NoSuchMethodException | IllegalAccessException | 
InvocationTargetException e) {
+                // ReflectiveOperationException
+                log.error(bean.getClass().getName() + ": unable to set 
property '" + property + "'");
+                throw new BeanPropertySetException(bean, property, e);  
+            } catch (NullPointerException e) {
+                // RuntimeException
+                log.error(bean.getClass().getName() + ": unable to set 
property '" + property + "'");
                 throw new BeanPropertySetException(bean, property, e);
             }
         }
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 d540822c..768ca61c 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
@@ -32,10 +32,9 @@ import java.lang.reflect.Modifier;
 import java.net.URISyntaxException;
 
 import org.apache.commons.beanutils.ConstructorUtils;
-import org.apache.empire.exceptions.EmpireException;
+import org.apache.empire.exceptions.BeanInstantiationException;
 import org.apache.empire.exceptions.InternalException;
 import org.apache.empire.exceptions.InvalidArgumentException;
-import org.apache.empire.exceptions.InvalidOperationException;
 import org.apache.empire.exceptions.NotImplementedException;
 import org.apache.empire.exceptions.NotSupportedException;
 import org.slf4j.Logger;
@@ -238,8 +237,10 @@ public final class ClassUtils
                     }
                     return copy;
                 }
-            } catch (InstantiationException | IllegalAccessException | 
IllegalArgumentException | InvocationTargetException e) {
-                log.error("Copy through Instantiation failed for : 
"+clazz.getName(), e);
+            } catch (InstantiationException | IllegalAccessException | 
InvocationTargetException e) {
+                // ReflectiveOperationException
+                Throwable cause = (e.getCause()!=null ? e.getCause() : e);
+                log.error("Copy through Instantiation failed for {}: {}", 
clazz.getName(), cause);
             }
         }
         // not supported
@@ -390,21 +391,13 @@ public final class ClassUtils
             Constructor<T> constructor = typeClass.getDeclaredConstructor();
             return constructor.newInstance();
         }
-        catch (NoSuchMethodException e)
-        {
-            throw new InvalidOperationException(typeClass.getName()+" has no 
default constructor.");
-        }
-        catch (InvocationTargetException e)
-        {   // Unwrap exception and re-throw the cause exception 
-            Throwable cause = e.getCause();
-            if (cause instanceof EmpireException)
-                throw (EmpireException)cause;
-            // wrap    
-            throw new InternalException(cause);
+        catch (InstantiationException | NoSuchMethodException | 
IllegalAccessException | InvocationTargetException e)
+        {   // ReflectiveOperationException
+            throw new BeanInstantiationException(typeClass, e);            
         }
-        catch (InstantiationException | IllegalAccessException | 
IllegalArgumentException | SecurityException e)
-        {
-            throw new InternalException(e);
+        catch (SecurityException e)
+        {   // RuntimeException
+            throw new BeanInstantiationException(typeClass, e);            
         }
     }
     
@@ -438,17 +431,13 @@ public final class ClassUtils
             // create
             return typeConstructor.newInstance(params);
         }
-        catch (InvocationTargetException e)
-        {   // Unwrap exception and re-throw the cause exception 
-            Throwable cause = e.getCause();
-            if (cause instanceof EmpireException)
-                throw (EmpireException)cause;
-            // wrap    
-            throw new InternalException(cause);
+        catch (InstantiationException | IllegalAccessException | 
InvocationTargetException e)
+        {   // ReflectiveOperationException
+            throw new BeanInstantiationException(typeConstructor, e);          
  
         }
-        catch (InstantiationException | IllegalAccessException | 
IllegalArgumentException e)
-        {
-            throw new InternalException(e);
+        catch (SecurityException | IllegalArgumentException e)
+        {   // RuntimeException
+            throw new BeanInstantiationException(typeConstructor, e);          
  
         }
     }
 
@@ -598,26 +587,14 @@ public final class ClassUtils
                 methodName += StringUtils.concat("({", 
String.valueOf(paramTypes.length), " params})");
             throw new NotImplementedException(object, methodName);
         }
-        catch (SecurityException e)
-        {   // Invalid Method definition   
-            throw new NotSupportedException(object, methodName, e);
-        }
-        catch (IllegalAccessException e)
-        {   // Invalid Method definition   
+        catch (IllegalAccessException | InvocationTargetException e)
+        {   // ReflectiveOperationException   
             throw new NotSupportedException(object, methodName, e);
         }
-        catch (IllegalArgumentException e)
-        {   // Invalid Method definition   
+        catch (SecurityException | IllegalArgumentException e)
+        {   // RuntimeException   
             throw new NotSupportedException(object, methodName, e);
         }
-        catch (InvocationTargetException e)
-        {   // Error inside Method
-            Throwable cause = e.getCause();
-            if (cause instanceof EmpireException)
-                throw (EmpireException)cause;
-            // wrap    
-            throw new InternalException(cause);
-        }
         finally {
             // restore accessible
             if (method!=null && accessible==false)
@@ -708,16 +685,12 @@ public final class ClassUtils
             // invoke
             return method.invoke(object, EMPTY_ARGS);
         }
-        catch (InvocationTargetException e)
-        {   // Unwrap exception and re-throw the cause exception 
-            Throwable cause = e.getCause();
-            if (cause instanceof EmpireException)
-                throw (EmpireException)cause;
-            // wrap    
-            throw new InternalException(cause);
+        catch (IllegalAccessException | InvocationTargetException e)
+        {   // ReflectiveOperationException 
+            throw new NotSupportedException(object, method.getName(), e); 
         }
-        catch (IllegalAccessException | IllegalArgumentException e)
-        {
+        catch (SecurityException | IllegalArgumentException e)
+        {   // RuntimeException
             throw new NotSupportedException(object, method.getName(), e); 
         } 
     }
@@ -740,16 +713,12 @@ public final class ClassUtils
             // invoke
             return method.invoke(object, params);
         }
-        catch (InvocationTargetException e)
-        {   // Unwrap exception and re-throw the cause exception 
-            Throwable cause = e.getCause();
-            if (cause instanceof EmpireException)
-                throw (EmpireException)cause;
-            // wrap    
-            throw new InternalException(cause);
+        catch (IllegalAccessException | InvocationTargetException e)
+        {   // ReflectiveOperationException 
+            throw new NotSupportedException(object, method.getName(), e); 
         }
-        catch (IllegalAccessException | IllegalArgumentException e)
-        {
+        catch (SecurityException | IllegalArgumentException e)
+        {   // RuntimeException
             throw new NotSupportedException(object, method.getName(), e); 
         } 
     }
diff --git 
a/empire-db/src/main/java/org/apache/empire/data/list/DataListEntry.java 
b/empire-db/src/main/java/org/apache/empire/data/list/DataListEntry.java
index 55f9e86c..d1e4e27a 100644
--- a/empire-db/src/main/java/org/apache/empire/data/list/DataListEntry.java
+++ b/empire-db/src/main/java/org/apache/empire/data/list/DataListEntry.java
@@ -294,7 +294,7 @@ public class DataListEntry implements RecordData, 
Serializable
      */
     public boolean isZero(ColumnExpr column)
     {
-        if (column==null || column.getDataType().isNumeric())
+        if (column==null || !column.getDataType().isNumeric())
             throw new InvalidArgumentException("column", column);
         // check for zero
         Object v = get(column);
diff --git 
a/empire-db/src/main/java/org/apache/empire/data/list/DataListFactoryImpl.java 
b/empire-db/src/main/java/org/apache/empire/data/list/DataListFactoryImpl.java
index 96a0eb1e..d2c7096b 100644
--- 
a/empire-db/src/main/java/org/apache/empire/data/list/DataListFactoryImpl.java
+++ 
b/empire-db/src/main/java/org/apache/empire/data/list/DataListFactoryImpl.java
@@ -26,7 +26,7 @@ import java.util.List;
 import org.apache.empire.commons.ClassUtils;
 import org.apache.empire.data.ColumnExpr;
 import org.apache.empire.data.RecordData;
-import org.apache.empire.exceptions.InternalException;
+import org.apache.empire.exceptions.BeanInstantiationException;
 import org.apache.empire.exceptions.InvalidArgumentException;
 import org.apache.empire.exceptions.NotSupportedException;
 import org.apache.empire.exceptions.UnsupportedTypeException;
@@ -119,21 +119,13 @@ public class DataListFactoryImpl<T extends DataListEntry> 
implements DataListFac
                     throw new UnsupportedTypeException(constructor.getClass());
             }
         }
-        catch (InstantiationException e)
-        {
-            throw new InternalException(e);
-        }
-        catch (IllegalAccessException e)
-        {
-            throw new InternalException(e);
+        catch (InstantiationException | IllegalAccessException | 
InvocationTargetException e)
+        {   // ReflectiveOperationException
+            throw new BeanInstantiationException(constructor, e);            
         }
         catch (IllegalArgumentException e)
-        {
-            throw new InternalException(e);
-        }
-        catch (InvocationTargetException e)
-        {
-            throw new InternalException(e);
+        {   // RuntimeException
+            throw new BeanInstantiationException(constructor, e);            
         }
     }
     
diff --git a/empire-db/src/main/java/org/apache/empire/db/DBObject.java 
b/empire-db/src/main/java/org/apache/empire/db/DBObject.java
index 92e52c91..ade7403e 100644
--- a/empire-db/src/main/java/org/apache/empire/db/DBObject.java
+++ b/empire-db/src/main/java/org/apache/empire/db/DBObject.java
@@ -23,7 +23,7 @@ import org.apache.empire.exceptions.InvalidArgumentException;
 /**
  * Base class for all objects that directly or indirectly belong to a database 
including the database object itself.
  * Examples are: tables, views, columns, indexes, relations etc.
- * Not included are: DBMSHanlders, helper classes
+ * Not included are: DBMSHandlers, helper classes
  */
 public abstract class DBObject // *Deprecated* implements Serializable
 {
diff --git a/empire-db/src/main/java/org/apache/empire/db/DBReader.java 
b/empire-db/src/main/java/org/apache/empire/db/DBReader.java
index 718828a0..d987173a 100644
--- a/empire-db/src/main/java/org/apache/empire/db/DBReader.java
+++ b/empire-db/src/main/java/org/apache/empire/db/DBReader.java
@@ -755,11 +755,8 @@ public class DBReader extends DBRecordData implements 
Closeable
             }
             // done
             return list;
-        } catch (InvocationTargetException e) {
-            throw new BeanInstantiationException(t, e);
-        } catch (IllegalAccessException e) {
-            throw new BeanInstantiationException(t, e);
-        } catch (InstantiationException e) {
+        } catch (InvocationTargetException | IllegalAccessException | 
InstantiationException e) {
+            // ReflectiveOperationException
             throw new BeanInstantiationException(t, e);
         }
     }
diff --git a/empire-db/src/main/java/org/apache/empire/db/DBRecordData.java 
b/empire-db/src/main/java/org/apache/empire/db/DBRecordData.java
index f0629ef1..c5d4004b 100644
--- a/empire-db/src/main/java/org/apache/empire/db/DBRecordData.java
+++ b/empire-db/src/main/java/org/apache/empire/db/DBRecordData.java
@@ -146,7 +146,7 @@ public abstract class DBRecordData extends DBObject
      */
     public boolean isZero(ColumnExpr column)
     {
-        if (column==null || column.getDataType().isNumeric())
+        if (column==null || !column.getDataType().isNumeric())
             throw new InvalidArgumentException("column", column);
         // check for zero
         Object v = get(column);
diff --git 
a/empire-db/src/main/java/org/apache/empire/db/list/DBBeanListFactoryImpl.java 
b/empire-db/src/main/java/org/apache/empire/db/list/DBBeanListFactoryImpl.java
index ce611915..daa07953 100644
--- 
a/empire-db/src/main/java/org/apache/empire/db/list/DBBeanListFactoryImpl.java
+++ 
b/empire-db/src/main/java/org/apache/empire/db/list/DBBeanListFactoryImpl.java
@@ -35,7 +35,7 @@ import org.apache.empire.db.DBCommandExpr;
 import org.apache.empire.db.DBContext;
 import org.apache.empire.db.DBRecordData;
 import org.apache.empire.db.exceptions.CommandWithoutSelectException;
-import org.apache.empire.exceptions.InternalException;
+import org.apache.empire.exceptions.BeanInstantiationException;
 import org.apache.empire.exceptions.InvalidArgumentException;
 import org.apache.empire.exceptions.UnsupportedTypeException;
 import org.slf4j.Logger;
@@ -284,9 +284,13 @@ public class DBBeanListFactoryImpl<T> implements 
DBBeanListFactory<T>
             }
             return bean;
         }
-        catch (InstantiationException | IllegalAccessException | 
IllegalArgumentException | InvocationTargetException e)
-        {
-            throw new InternalException(e);
+        catch (InstantiationException | IllegalAccessException | 
InvocationTargetException e)
+        {   // ReflectiveOperationException
+            throw new BeanInstantiationException(constructor, e);            
+        }
+        catch (IllegalArgumentException e)
+        {   // RuntimeException
+            throw new BeanInstantiationException(constructor, 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 f9d7f6db..fec66a10 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
@@ -33,6 +33,7 @@ import org.apache.empire.db.DBRecordBase.State;
 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;
@@ -155,9 +156,13 @@ public class DBRecordListFactoryImpl<T extends 
DBRecordBase> implements DBRecord
                 rowset.initRecord(record, recData, (state==State.New));
             return record;
         }
-        catch (InstantiationException | IllegalAccessException | 
IllegalArgumentException | InvocationTargetException e)
-        {
-            throw new InternalException(e);
+        catch (InstantiationException | IllegalAccessException | 
InvocationTargetException e)
+        {   // ReflectiveOperationException
+            throw new BeanInstantiationException(constructor, e);            
+        }
+        catch (IllegalArgumentException e)
+        {   // RuntimeException
+            throw new BeanInstantiationException(constructor, e);            
         }
     }
     
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 cee83189..d54b81e2 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
@@ -18,6 +18,8 @@
  */
 package org.apache.empire.exceptions;
 
+import java.lang.reflect.Constructor;
+
 import org.apache.empire.commons.ErrorType;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -31,9 +33,24 @@ public class BeanInstantiationException extends 
EmpireException
     
     public static final ErrorType errorType = new 
ErrorType("error.beanInstantiationFailed", "Unable create an instance of type 
{0}.");
     
-    public BeanInstantiationException(Class<?> clazz, Throwable cause)
+    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)
     {
-        super(errorType, new String[] { clazz.getName() }, cause);
+        this(c.getDeclaringClass(), 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 216baa49..e2e83b5c 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
@@ -31,9 +31,14 @@ public class BeanPropertyGetException extends EmpireException
     
     public static final ErrorType errorType = new 
ErrorType("error.propertyGetError", "Unable to get the property {0} from type 
{1}.");
     
-    public BeanPropertyGetException(Object bean, String property, Throwable 
cause)
+    public BeanPropertyGetException(Object bean, String property, 
ReflectiveOperationException e)
     {
-        super(errorType, new String[] { property, (bean!=null ? 
bean.getClass().getName() : "{unknown}") }, cause);
+        super(errorType, new String[] { property, (bean!=null ? 
bean.getClass().getName() : "{unknown}") }, getCause(e));
+    }
+    
+    public BeanPropertyGetException(Object bean, String property, 
RuntimeException e)
+    {
+        super(errorType, new String[] { property, (bean!=null ? 
bean.getClass().getName() : "{unknown}") }, e);
     }
     
     /**
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 e10131dc..0613001a 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
@@ -30,10 +30,15 @@ public class BeanPropertySetException extends 
EmpireException
     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, Throwable 
cause)
+    public BeanPropertySetException(Object bean, String property, 
RuntimeException e)
     {
-        super(errorType, new String[] { property, (bean!=null ? 
bean.getClass().getName() : "{unknown}") }, cause);
+        super(errorType, new String[] { property, (bean!=null ? 
bean.getClass().getName() : "{unknown}") }, e);
     }
     
     /**
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 9ad3aee7..5877290b 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,6 +123,24 @@ 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/InternalException.java 
b/empire-db/src/main/java/org/apache/empire/exceptions/InternalException.java
index 6909bc00..38e1256d 100644
--- 
a/empire-db/src/main/java/org/apache/empire/exceptions/InternalException.java
+++ 
b/empire-db/src/main/java/org/apache/empire/exceptions/InternalException.java
@@ -38,7 +38,7 @@ public class InternalException extends EmpireException
         if (type.startsWith("java.lang."))
             type = type.substring("java.lang.".length());
         // The message
-        String msg   = exptn.getMessage();
+        String msg = exptn.getMessage();
         // Prepare stack trace
         StackTraceElement[] stack = exptn.getStackTrace();
         String pos = (stack!=null && stack.length>0) ? stack[0].toString() : 
"{unknown}";
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 464d2867..12452508 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,14 +38,19 @@ public class NotSupportedException extends EmpireException
         return "-";
     }
     
-    public NotSupportedException(Object object, String operationName, 
Exception e)
+    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)
     {
         super(errorType, new String[] { operationName, typeFromObject(object) 
}, e);
     }
     
     public NotSupportedException(Object object, String operationName)
     {
-        this(object, operationName, null);
+        super(errorType, new String[] { operationName, typeFromObject(object) 
});
     }
 
 }
diff --git 
a/empire-db/src/main/java/org/apache/empire/xml/XMLConfiguration.java 
b/empire-db/src/main/java/org/apache/empire/xml/XMLConfiguration.java
index f5842367..cc782f75 100644
--- a/empire-db/src/main/java/org/apache/empire/xml/XMLConfiguration.java
+++ b/empire-db/src/main/java/org/apache/empire/xml/XMLConfiguration.java
@@ -286,10 +286,11 @@ public class XMLConfiguration
             setPropertyValue(bean, name, newValue);
         } catch (IllegalAccessException e) {
             log.error("Config error: Access to '{}' in {} denied.", prop, 
bean.getClass().getName(), e);
-        } catch (InvocationTargetException e) {
-            log.error("Config error: Unable to set value for '{}' in {}", 
prop, bean.getClass().getName(), e);
         } catch (NoSuchMethodException e) {
             log.error("Config error: Property '{}' in {} not found. Property 
is ignored.", prop, bean.getClass().getName(), e);
+        } catch (InvocationTargetException e) {
+            Throwable cause = (e.getCause()!=null ? e.getCause() : e);
+            log.error("Config error: Unable to set value for '{}' in {}", 
prop, bean.getClass().getName(), cause);
         } catch (EmpireException e) {
             log.error("Config error: Invalid Value for '{}' in {}", prop, 
bean.getClass().getName(), e);
         }
@@ -435,9 +436,10 @@ public class XMLConfiguration
                 b.append(String.valueOf(value));
                 b.append(EOL);
             }
-            catch (IllegalAccessException | InvocationTargetException | 
NoSuchMethodException e)
+            catch (NoSuchMethodException | IllegalAccessException | 
InvocationTargetException e)
             {
-                log.warn("Field {} is ignored due to Exception {}", 
field.getName(), e.toString());
+                Throwable cause = (e.getCause()!=null ? e.getCause() : e);
+                log.warn("Field {} is ignored due to Exception {}", 
field.getName(), cause.toString());
             }
         }
         if (appendClassInfo==false)

Reply via email to