Uploaded image for project: 'Commons Lang'
  1. Commons Lang
  2. LANG-105

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

    Details

    • Type: Bug
    • Status: Closed
    • Priority: 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

    • Bugzilla Id:
      37038

      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

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              andylehane@hotmail.com Andy Lehane
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: