DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUGĀ·
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=37038>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED ANDĀ·
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=37038

           Summary: ExceptionUtils goes into infinite loop in getThrowables
                    is throwable.getCause() == throwable
           Product: Commons
           Version: 2.1 Final
          Platform: PC
        OS/Version: Windows 2000
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Lang
        AssignedTo: commons-dev@jakarta.apache.org
        ReportedBy: [EMAIL PROTECTED]


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

-- 
Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to