Commons Lang
  1. Commons Lang
  2. LANG-212

[lang] [PATCH] New ExceptionUtils method setCause()

    Details

    • Type: Improvement Improvement
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 2.2
    • Component/s: None
    • Labels:
      None
    • Environment:

      Operating System: other
      Platform: Other

      Description

      Hi people,

      the purpose of the ExceptionUtils.setCause() method I am proposing is to
      preserve the standard JDK 1.4 exception

      nesting mechanism even when targeting source code for a prior JDK 1.4 version.

      ExceptionUtils.setCause(), which can be thought as the counterpart of
      ExceptionUtils.getCause(), calls via

      introspection on the target Throwable the 2 following methods:

      <Object>.setCause(Throwable)
      <Object>.initCause(Throwable)

      The typical use of ExceptionUtils.setCause() is inside a constructor, as in
      the following example:

      import org.apache.commons.lang.exception.ExceptionUtils;

      public class MyException extends Exception {

      public MyException(String msg)

      { super(msg); }

      public MyException(String msg, Throwable cause)

      { super(msg); ExceptionUtils.setCause(this, cause); }

      }

      I hope this can be useful for whom who are maintaining code that must be
      portable on both the JDK 1.3 and JDK 1.4+

      environments.

      Andrea.

        Activity

        Hide
        Andrea Rombaldi added a comment -

        Created an attachment (id=17007)
        ExceptionUtils.patch

        Show
        Andrea Rombaldi added a comment - Created an attachment (id=17007) ExceptionUtils.patch
        Hide
        ggregory@seagullsw.com added a comment -

        Please provide a unit test to validate your patch. I can then take a look at
        merging your code with much less effort as I do not want to take the time to
        write the tests myself.
        Thank you,
        Gary

        Show
        ggregory@seagullsw.com added a comment - Please provide a unit test to validate your patch. I can then take a look at merging your code with much less effort as I do not want to take the time to write the tests myself. Thank you, Gary
        Hide
        Andrea Rombaldi added a comment -

        Created an attachment (id=17055)
        Patch to implement ExceptionUtils.setCause(Throwable, Throwable)

        This patch replaces the previous patch to implement
        ExceptionUtils.setCause(Throwable, Throwable)

        Show
        Andrea Rombaldi added a comment - Created an attachment (id=17055) Patch to implement ExceptionUtils.setCause(Throwable, Throwable) This patch replaces the previous patch to implement ExceptionUtils.setCause(Throwable, Throwable)
        Hide
        Andrea Rombaldi added a comment -

        Created an attachment (id=17056)
        Test Case for ExceptionUtils.setCause(Throwable, Throwable)

        Show
        Andrea Rombaldi added a comment - Created an attachment (id=17056) Test Case for ExceptionUtils.setCause(Throwable, Throwable)
        Hide
        Andrea Rombaldi added a comment -

        Hello,

        does any commons-lang committer have the time to take a short look to the
        patches I provided?

        Thank you in advance.
        Andrea.

        Show
        Andrea Rombaldi added a comment - Hello, does any commons-lang committer have the time to take a short look to the patches I provided? Thank you in advance. Andrea.
        Hide
        ggregory@seagullsw.com added a comment -

        I'll try to take a look this week.

        Show
        ggregory@seagullsw.com added a comment - I'll try to take a look this week.
        Hide
        ggregory@seagullsw.com added a comment -

        Code and tests tweaked and committed. Added one more test method.

        Show
        ggregory@seagullsw.com added a comment - Code and tests tweaked and committed. Added one more test method.

          People

          • Assignee:
            Unassigned
            Reporter:
            Andrea Rombaldi
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development