From c104890f334612d9045b03d48b15ed2689f6444b Mon Sep 17 00:00:00 2001 From: PJ Fanning Date: Wed, 14 Jul 2021 21:53:22 +0000 Subject: [PATCH] add extra debug logging to failing tests git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1891554 13f79535-47bb-0310-9956-ffa450edef68 --- .../java/org/apache/poi/stress/OPCFileHandler.java | 7 ++++++- .../java/org/apache/poi/stress/XWPFFileHandler.java | 13 ++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/poi-integration/src/test/java/org/apache/poi/stress/OPCFileHandler.java b/poi-integration/src/test/java/org/apache/poi/stress/OPCFileHandler.java index 2bbd9fc70a..e5493d01bd 100644 --- a/poi-integration/src/test/java/org/apache/poi/stress/OPCFileHandler.java +++ b/poi-integration/src/test/java/org/apache/poi/stress/OPCFileHandler.java @@ -36,7 +36,12 @@ class OPCFileHandler extends AbstractFileHandler { // ignore password protected files if (POIXMLDocumentHandler.isEncrypted(stream)) return; - OPCPackage p = OPCPackage.open(stream); + OPCPackage p; + try { + p = OPCPackage.open(stream); + } catch (Exception e) { + throw new RuntimeException("Failed to open '" + path + "' as OPCPackage", e); + } for (PackagePart part : p.getParts()) { if (part.getPartName().toString().equals("/docProps/core.xml")) { diff --git a/poi-integration/src/test/java/org/apache/poi/stress/XWPFFileHandler.java b/poi-integration/src/test/java/org/apache/poi/stress/XWPFFileHandler.java index 0970d4fa1a..dbbb3f5edd 100644 --- a/poi-integration/src/test/java/org/apache/poi/stress/XWPFFileHandler.java +++ b/poi-integration/src/test/java/org/apache/poi/stress/XWPFFileHandler.java @@ -20,24 +20,31 @@ import java.io.BufferedInputStream; import java.io.File; import java.io.FileInputStream; import java.io.InputStream; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashSet; +import java.util.Set; import org.apache.poi.ooxml.POIXMLException; +import org.apache.poi.openxml4j.opc.OPCPackage; import org.apache.poi.xwpf.usermodel.XWPFDocument; import org.junit.jupiter.api.Test; class XWPFFileHandler extends AbstractFileHandler { + @Override public void handleFile(InputStream stream, String path) throws Exception { // ignore password protected files if (POIXMLDocumentHandler.isEncrypted(stream)) return; try (XWPFDocument doc = new XWPFDocument(stream)) { - new POIXMLDocumentHandler().handlePOIXMLDocument(doc); POIXMLDocumentHandler.cursorRecursive(doc.getDocument()); } catch (POIXMLException e) { Exception cause = (Exception)e.getCause(); throw cause == null ? e : cause; + } catch (Exception e) { + throw new RuntimeException("Failed to open '" + path + "' as XWPFDocument", e); } } @@ -53,4 +60,8 @@ class XWPFFileHandler extends AbstractFileHandler { handleExtracting(file); } + + private static Set unmodifiableHashSet(String... a) { + return Collections.unmodifiableSet(new HashSet<>(Arrays.asList(a))); + } } \ No newline at end of file -- 2.39.5