From 475f7ee866348015e642dfa9c79706c769bfd89c Mon Sep 17 00:00:00 2001 From: Javen O'Neal Date: Wed, 14 Sep 2016 13:28:27 +0000 Subject: [PATCH] give more helpful exceptions rather than returning null when zip file cannot be opened git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1760708 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/poi/openxml4j/opc/internal/ZipHelper.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/ZipHelper.java b/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/ZipHelper.java index 632d2af262..b674b3ad2f 100644 --- a/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/ZipHelper.java +++ b/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/ZipHelper.java @@ -19,6 +19,7 @@ package org.apache.poi.openxml4j.opc.internal; import java.io.File; import java.io.FileInputStream; +import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.io.PushbackInputStream; @@ -239,10 +240,15 @@ public final class ZipHelper { * @param file * The file to open. * @return The zip archive freshly open. + * @throws IOException if the zip file cannot be opened or closed to read the header signature + * @throws NotOfficeXmlFileException if stream does not start with zip header signature */ - public static ZipFile openZipFile(File file) throws IOException { + public static ZipFile openZipFile(File file) throws IOException, NotOfficeXmlFileException { if (!file.exists()) { - return null; + throw new FileNotFoundException("File does not exist"); + } + if (file.isDirectory()) { + throw new IOException("File is a directory"); } // Peek at the first few bytes to sanity check -- 2.39.5