Uploaded image for project: 'Commons BeanUtils'
  1. Commons BeanUtils
  2. BEANUTILS-297

ConvertingWrapDynaBean hides cause exceptions

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.8.0-BETA
    • 1.8.0
    • DynaBean
    • None

    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); }

      Attachments

        Activity

          People

            Unassigned Unassigned
            alextk Alex Tkachev
            Votes:
            2 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: