Description
ConvertingWrapDynaBean.set(String,Object) method hides cause exception.
This issue relates to BEANUTILS-23 that partially fixed this problem, by adding only the message of the cause exception to IllegalArgumentException that is being thrown:
try
{ BeanUtils.copyProperty(instance, name, value); } catch (InvocationTargetException ite) { Throwable cause = ite.getTargetException(); throw new IllegalArgumentException ("Error setting property '" + name + "' nested exception - " + cause); } catch (Throwable t) { throw new IllegalArgumentException ("Error setting property '" + name + "', exception - " + t); }I think that the cause exception (ie Throwable t) should be passed to newly generated IllegalArgumentException (as second parameter). I don't really see no good in hiding it, it only causes problems in identifying the cause why the setter has failed. Good example why this is important is using Jelly. If for some reason the setter fails (for instance, some illegal value was passed and nested exception was thrown by the setter), you have no way of knowing the cause of it. The only way to find out the real cause is through debugging, setting some complex conditional breakpoints.
My proposed code is:
try { BeanUtils.copyProperty(instance, name, value); }
catch (InvocationTargetException ite)
{ Throwable cause = ite.getTargetException(); throw new IllegalArgumentException ("Error setting property '" + name + "' nested exception - " + cause, t); }catch (Throwable t)
{ throw new IllegalArgumentException ("Error setting property '" + name + "', exception - " + t, t); }