class ExceptionUtils {
/**
* <p>Removes common frames from the cause trace given the two stack traces.</p>
*
* @param causeFrames stack trace of a cause throwable
* @param wrapperFrames stack trace of a wrapper throwable
* @throws IllegalArgumentException if either argument is null
* @since 2.0
*/
public static void removeCommonFrames(List causeFrames, List wrapperFrames) {
if (causeFrames == null || wrapperFrames == null) {
throw new IllegalArgumentException("The List must not be null");
}
int causeFrameIndex = causeFrames.size() - 1;
int wrapperFrameIndex = wrapperFrames.size() - 1;
while (causeFrameIndex >= 0 && wrapperFrameIndex >= 0) {
// Remove the frame from the cause trace if it is the same
// as in the wrapper trace
String causeFrame = (String) causeFrames.get(causeFrameIndex);
String wrapperFrame = (String) wrapperFrames.get(wrapperFrameIndex);
if (causeFrame.equals(wrapperFrame)) {
causeFrames.remove(causeFrameIndex);
}
causeFrameIndex--;
wrapperFrameIndex--;
}
}
}