package org.apache.ibatis.reflection;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.UndeclaredThrowableException;

public class ExceptionUtil {

  public static Throwable unwrapThrowable(Throwable wrapped) {
    Throwable unwrapped = wrapped;
    while (true) {
      if (unwrapped instanceof InvocationTargetException) {
        unwrapped = ((InvocationTargetException) wrapped).getTargetException();
      } else if (unwrapped instanceof UndeclaredThrowableException) {
        unwrapped = ((UndeclaredThrowableException) wrapped).getUndeclaredThrowable();
      } else {
        return unwrapped;
      }
    }
  }

}

@@ -399,32 +399,34 @@
 argetException) 
+un
 wrapped).getTarg
@@ -564,16 +564,18 @@
 eption) 
+un
 wrapped)

fix for issue #275, bug in unwrapping loop