aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDominik Stadler <centic@apache.org>2019-04-07 07:17:41 +0000
committerDominik Stadler <centic@apache.org>2019-04-07 07:17:41 +0000
commitb88c6b12e5679b74287e8b62089af05f5091c035 (patch)
tree74ff514ab8a504203ba1cf1040351b54e1281188
parent9b726e88b72f7772297709d651d40eeccdd2a342 (diff)
downloadpoi-b88c6b12e5679b74287e8b62089af05f5091c035.tar.gz
poi-b88c6b12e5679b74287e8b62089af05f5091c035.zip
Improve error message slightly and verify error when a File is passed in
as "Object" git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1857067 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--src/java/org/apache/poi/ss/usermodel/WorkbookFactory.java5
-rw-r--r--src/ooxml/testcases/org/apache/poi/ss/TestWorkbookFactory.java10
2 files changed, 13 insertions, 2 deletions
diff --git a/src/java/org/apache/poi/ss/usermodel/WorkbookFactory.java b/src/java/org/apache/poi/ss/usermodel/WorkbookFactory.java
index ca291a68a7..157dcb50b1 100644
--- a/src/java/org/apache/poi/ss/usermodel/WorkbookFactory.java
+++ b/src/java/org/apache/poi/ss/usermodel/WorkbookFactory.java
@@ -23,6 +23,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
+import java.util.Arrays;
import org.apache.poi.EncryptedDocumentException;
import org.apache.poi.OldFileFormatException;
@@ -351,8 +352,8 @@ public class WorkbookFactory {
throw new IOException(t.getMessage(), t);
}
} catch (Exception e) {
- throw new IOException(e);
+ throw new IOException("While trying to invoke 'createWorkbook' on factory " + factoryClass +
+ " and arguments " + Arrays.toString(args), e);
}
}
-
}
diff --git a/src/ooxml/testcases/org/apache/poi/ss/TestWorkbookFactory.java b/src/ooxml/testcases/org/apache/poi/ss/TestWorkbookFactory.java
index c4c68b9717..8309f05ff4 100644
--- a/src/ooxml/testcases/org/apache/poi/ss/TestWorkbookFactory.java
+++ b/src/ooxml/testcases/org/apache/poi/ss/TestWorkbookFactory.java
@@ -420,6 +420,16 @@ public final class TestWorkbookFactory {
assertNotNull(wb);
assertTrue(wb instanceof XSSFWorkbook);
closeOrRevert(wb);
+
+ // check what happens if the file is passed as "Object"
+
+ try {
+ //noinspection deprecation
+ WorkbookFactory.create((Object)altXLSX);
+ fail("Will throw an exception");
+ } catch(IOException e) {
+ // expected here because create() in this case expects an object of type "OPCPackage"
+ }
}
private static class TestFile extends File {