]> source.dussan.org Git - poi.git/commitdiff
Include actual found type in exception when encountering unexpected type of file...
authorDominik Stadler <centic@apache.org>
Mon, 20 May 2019 14:42:39 +0000 (14:42 +0000)
committerDominik Stadler <centic@apache.org>
Mon, 20 May 2019 14:42:39 +0000 (14:42 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1859565 13f79535-47bb-0310-9956-ffa450edef68

src/ooxml/java/org/apache/poi/ooxml/extractor/ExtractorFactory.java
src/ooxml/testcases/org/apache/poi/extractor/ooxml/TestExtractorFactory.java

index 70360e64e50d305cb3c939f31398b6a97b15a674..bf8771bda29ff38e1505a1ad72eb640c3b2eedbd 100644 (file)
@@ -167,7 +167,7 @@ public final class ExtractorFactory {
         case OOXML:
             return createExtractor(OPCPackage.open(is));
         default:
-            throw new IllegalArgumentException("Your InputStream was neither an OLE2 stream, nor an OOXML stream");
+            throw new IllegalArgumentException("Your InputStream was neither an OLE2 stream, nor an OOXML stream, found type: " + fm);
         }
     }
 
index 851f9dd089ad4889ae6ce533819fedc6b0a03e7a..a8755e960121f2bd214f27217c535e62173c0dea 100644 (file)
@@ -42,6 +42,7 @@ import org.apache.poi.ooxml.extractor.POIXMLTextExtractor;
 import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
 import org.apache.poi.openxml4j.opc.OPCPackage;
 import org.apache.poi.openxml4j.opc.PackageAccess;
+import org.apache.poi.poifs.filesystem.FileMagic;
 import org.apache.poi.poifs.filesystem.POIFSFileSystem;
 import org.apache.poi.xssf.extractor.XSSFEventBasedExcelExtractor;
 import org.apache.poi.xssf.extractor.XSSFExcelExtractor;
@@ -193,6 +194,11 @@ public class TestExtractorFactory {
         try (FileInputStream fis = new FileInputStream(txt);
              POITextExtractor ignored = poifs.apply(fis)) {
             fail("extracting from invalid package");
+        } catch (IllegalArgumentException e) {
+            assertTrue("Had: " + e,
+                    e.getMessage().contains(FileMagic.UNKNOWN.name()));
+
+            throw e;
         }
     }