XGC-98: UndeclaredThrowableException while loading images

git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/commons/trunk@1723030 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/src/java/org/apache/xmlgraphics/image/loader/impl/AbstractImageSessionContext.java b/src/java/org/apache/xmlgraphics/image/loader/impl/AbstractImageSessionContext.java
index ba5c37d..b91a728 100644
--- a/src/java/org/apache/xmlgraphics/image/loader/impl/AbstractImageSessionContext.java
+++ b/src/java/org/apache/xmlgraphics/image/loader/impl/AbstractImageSessionContext.java
@@ -24,6 +24,7 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 import java.lang.reflect.Proxy;
 import java.net.MalformedURLException;
@@ -119,15 +120,19 @@
 
         /** {@inheritDoc} */
         public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
-            if ("close".equals(method.getName())) {
-                try {
+            try {
+                if ("close".equals(method.getName())) {
+                    try {
+                        return method.invoke(iin, args);
+                    } finally {
+                        IOUtils.closeQuietly(this.in);
+                        this.in = null;
+                    }
+                } else {
                     return method.invoke(iin, args);
-                } finally {
-                    IOUtils.closeQuietly(this.in);
-                    this.in = null;
                 }
-            } else {
-                return method.invoke(iin, args);
+            } catch (InvocationTargetException e) {
+                throw e.getCause();
             }
         }