You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Niall Pemberton (JIRA)" <ji...@apache.org> on 2007/10/18 17:23:51 UTC

[jira] Commented: (BEANUTILS-297) ConvertingWrapDynaBean hides cause exceptions

    [ https://issues.apache.org/jira/browse/BEANUTILS-297?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12535939 ] 

Niall Pemberton commented on BEANUTILS-297:
-------------------------------------------

BeanUtils still has a minimum dependency of JDK 1.3 and the constructor which takes the "cause exception" was not added until JDK 1.4 so we can't resolve this the way you propose. However to resolve the same type of issue for BEANUTILS-266 we added an initCause() method which uses reflection for JDK 1.4+ to initialize the cause (see http://tinyurl.com/25nx5e) - so we can use that.



> ConvertingWrapDynaBean hides cause exceptions
> ---------------------------------------------
>
>                 Key: BEANUTILS-297
>                 URL: https://issues.apache.org/jira/browse/BEANUTILS-297
>             Project: Commons BeanUtils
>          Issue Type: Improvement
>          Components: DynaBean
>    Affects Versions: 1.8.0-BETA
>            Reporter: Alex Tkachev
>             Fix For: 1.8.0
>
>
> 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);
>         }

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.