From 1a3e69fe167598ebe247408cdb15c3aa152a0bc0 Mon Sep 17 00:00:00 2001 From: Dominik Stadler Date: Mon, 20 May 2019 14:42:39 +0000 Subject: [PATCH] Include actual found type in exception when encountering unexpected type of file in ExtractorFactory git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1859565 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/poi/ooxml/extractor/ExtractorFactory.java | 2 +- .../apache/poi/extractor/ooxml/TestExtractorFactory.java | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/ooxml/java/org/apache/poi/ooxml/extractor/ExtractorFactory.java b/src/ooxml/java/org/apache/poi/ooxml/extractor/ExtractorFactory.java index 70360e64e5..bf8771bda2 100644 --- a/src/ooxml/java/org/apache/poi/ooxml/extractor/ExtractorFactory.java +++ b/src/ooxml/java/org/apache/poi/ooxml/extractor/ExtractorFactory.java @@ -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); } } diff --git a/src/ooxml/testcases/org/apache/poi/extractor/ooxml/TestExtractorFactory.java b/src/ooxml/testcases/org/apache/poi/extractor/ooxml/TestExtractorFactory.java index 851f9dd089..a8755e9601 100644 --- a/src/ooxml/testcases/org/apache/poi/extractor/ooxml/TestExtractorFactory.java +++ b/src/ooxml/testcases/org/apache/poi/extractor/ooxml/TestExtractorFactory.java @@ -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; } } -- 2.39.5