From a12c95990b3e89158637339a62f8f617a4d91742 Mon Sep 17 00:00:00 2001 From: PJ Fanning Date: Tue, 2 Jul 2024 00:02:47 +0000 Subject: try to fix tests git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1918808 13f79535-47bb-0310-9956-ffa450edef68 --- .../src/main/java/org/apache/poi/ooxml/util/PackageHelper.java | 8 +++++--- .../src/main/java/org/apache/poi/openxml4j/opc/OPCPackage.java | 3 ++- 2 files changed, 7 insertions(+), 4 deletions(-) (limited to 'poi-ooxml') diff --git a/poi-ooxml/src/main/java/org/apache/poi/ooxml/util/PackageHelper.java b/poi-ooxml/src/main/java/org/apache/poi/ooxml/util/PackageHelper.java index 119289cfd4..a7b7f8c1e5 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/ooxml/util/PackageHelper.java +++ b/poi-ooxml/src/main/java/org/apache/poi/ooxml/util/PackageHelper.java @@ -48,6 +48,7 @@ public final class PackageHelper { * @param stream The InputStream to read from - which is closed when it is read * @return OPCPackage * @throws IOException If reading data from the stream fails + * @throws POIXMLException If the stream is not a valid OPC package */ public static OPCPackage open(InputStream stream) throws IOException { return open(stream, true); @@ -58,6 +59,7 @@ public final class PackageHelper { * @param closeStream whether to close the stream * @return OPCPackage * @throws IOException If reading data from the stream fails + * @throws POIXMLException If the stream is not a valid OPC package * @since POI 5.2.0 */ public static OPCPackage open(InputStream stream, boolean closeStream) throws IOException { @@ -65,10 +67,10 @@ public final class PackageHelper { return OPCPackage.open(stream, closeStream); } catch (InvalidFormatException e) { final Throwable cause = e.getCause(); - if (cause instanceof IOException) { - throw (IOException) cause; + if (cause instanceof InvalidZipException) { + throw (InvalidZipException) cause; } - throw new IOException(e); + throw new POIXMLException(e); } finally { if (closeStream) { stream.close(); diff --git a/poi-ooxml/src/main/java/org/apache/poi/openxml4j/opc/OPCPackage.java b/poi-ooxml/src/main/java/org/apache/poi/openxml4j/opc/OPCPackage.java index 0b476b1b12..d43ccef578 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/openxml4j/opc/OPCPackage.java +++ b/poi-ooxml/src/main/java/org/apache/poi/openxml4j/opc/OPCPackage.java @@ -326,7 +326,8 @@ public abstract class OPCPackage implements RelationshipSource, Closeable { pack = new ZipPackage(in, PackageAccess.READ_WRITE); } catch (InvalidZipException e) { throw new InvalidFormatException(e.getMessage(), e); - } try { + } + try { if (pack.partList == null) { pack.getParts(); } -- cgit v1.2.3