You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by bu...@apache.org on 2005/10/12 10:02:12 UTC
DO NOT REPLY [Bug 37038] New: -
ExceptionUtils goes into infinite loop in getThrowables is throwable.getCause() == throwable
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: andylehane@hotmail.com
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: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org