Commons Lang
  1. Commons Lang
  2. LANG-105

[lang] ExceptionUtils goes into infinite loop in getThrowables is throwable.getCause() == throwable

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.1
    • Fix Version/s: 2.2
    • Component/s: None
    • Labels:
      None
    • Environment:

      Operating System: Windows 2000
      Platform: PC

      Description

      The ExceptionUtils.getThrowables(throwable) can loop for ever if
      throwable.getCause() == throwable.

      The following code should fix this:

      public static Throwable[] getThrowables(final Throwable throwable) {
      List list = new ArrayList();

      if (throwable != null) {
      Throwable cause = throwable.getCause();
      list.add(throwable);
      while (cause != null && cause != throwable)

      { list.add(cause); cause = ExceptionUtils.getCause(cause); }

      }

      return (Throwable[]) list.toArray(new Throwable[list.size()]);
      }

      Also, the getCauseUsingWellKnownTypes(throwable) should be enhanced to avoid the
      same problems:

      private static Throwable getCauseUsingWellKnownTypes(Throwable throwable) {
      if (throwable instanceof Nestable && throwable.getCause() != throwable)

      { return ((Nestable) throwable).getCause(); }

      else if (throwable instanceof SQLException)

      { return ((SQLException) throwable).getNextException(); }

      else if (throwable instanceof InvocationTargetException)

      { return ((InvocationTargetException) throwable).getTargetException(); }

      else

      { return null; }

      }

      Cheers

      Andy

        Activity

        Andy Lehane created issue -
        Hide
        ggregory@seagullsw.com added a comment -

        Could you provide a unit test patch that reproduces the problem? Thank you.

        Show
        ggregory@seagullsw.com added a comment - Could you provide a unit test patch that reproduces the problem? Thank you.
        Hide
        Stephen Colebourne added a comment -

        Fixed in SVN

        Show
        Stephen Colebourne added a comment - Fixed in SVN
        Henri Yandell made changes -
        Field Original Value New Value
        issue.field.bugzillaimportkey 37038 12342623
        Henri Yandell made changes -
        Component/s Lang [ 12311121 ]
        Fix Version/s 2.2 [ 12311686 ]
        Assignee Jakarta Commons Developers Mailing List [ commons-dev@jakarta.apache.org ]
        Project Commons [ 12310458 ] Commons Lang [ 12310481 ]
        Affects Version/s 2.1 Final [ 12311659 ]
        Key COM-2471 LANG-105
        Henri Yandell made changes -
        Affects Version/s 2.1 Final [ 12311701 ]
        Henri Yandell made changes -
        Fix Version/s 2.2 [ 12311702 ]
        Henri Yandell made changes -
        Status Resolved [ 5 ] Closed [ 6 ]
        Mark Thomas made changes -
        Workflow jira [ 12371528 ] Default workflow, editable Closed status [ 12602393 ]

          People

          • Assignee:
            Unassigned
            Reporter:
            Andy Lehane
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development