diff --git a/poi-ooxml/src/main/java/org/apache/poi/xslf/XSLFReadException.java b/poi-ooxml/src/main/java/org/apache/poi/xslf/XSLFReadException.java index bdb8c800d1..e26900cde8 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xslf/XSLFReadException.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xslf/XSLFReadException.java @@ -19,7 +19,8 @@ package org.apache.poi.xslf; import org.apache.poi.POIException; /** - * An exception that indicates a problem reading a pptx file. + * An exception that indicates a problem reading a pptx file. Usually, a more + * specific exception will be wrapped as the cause. *
This exception is only used by some new methods. * Historically, POI has used {@link RuntimeException} for most of its * exceptions, but this is not a good practice. This class is a checked diff --git a/poi-ooxml/src/main/java/org/apache/poi/xssf/XSSFReadException.java b/poi-ooxml/src/main/java/org/apache/poi/xssf/XSSFReadException.java index 545dd0ffbf..f2dbac32c9 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xssf/XSSFReadException.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xssf/XSSFReadException.java @@ -19,7 +19,8 @@ package org.apache.poi.xssf; import org.apache.poi.POIException; /** - * An exception that indicates a problem reading an xlsx file. + * An exception that indicates a problem reading an xlsx file. Usually, a more + * specific exception will be wrapped as the cause. *
This exception is only used by some new methods. * Historically, POI has used {@link RuntimeException} for most of its * exceptions, but this is not a good practice. This class is a checked diff --git a/poi-ooxml/src/main/java/org/apache/poi/xwpf/XWPFReadException.java b/poi-ooxml/src/main/java/org/apache/poi/xwpf/XWPFReadException.java index 1b0e6a5bae..3379b16999 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xwpf/XWPFReadException.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xwpf/XWPFReadException.java @@ -19,7 +19,8 @@ package org.apache.poi.xwpf; import org.apache.poi.POIException; /** - * An exception that indicates a problem reading a docx file. + * An exception that indicates a problem reading a docx file. Usually, a more + * specific exception will be wrapped as the cause. *
This exception is only used by some new methods. * Historically, POI has used {@link RuntimeException} for most of its * exceptions, but this is not a good practice. This class is a checked diff --git a/poi-ooxml/src/test/java/org/apache/poi/xssf/TestXSSFParser.java b/poi-ooxml/src/test/java/org/apache/poi/xssf/TestXSSFParser.java new file mode 100644 index 0000000000..3d60986240 --- /dev/null +++ b/poi-ooxml/src/test/java/org/apache/poi/xssf/TestXSSFParser.java @@ -0,0 +1,47 @@ +/* ==================================================================== + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +==================================================================== */ + +package org.apache.poi.xssf; + +import java.io.File; + +import org.apache.poi.hssf.HSSFTestDataSamples; +import org.apache.poi.xssf.usermodel.XSSFWorkbook; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; + +public class TestXSSFParser { + @Test + void testXlsx() throws Exception { + final File file = HSSFTestDataSamples.getSampleFile("HeaderFooterComplexFormats.xlsx"); + try (XSSFWorkbook wb = XSSFParser.parse(file)) { + assertNotNull(wb); + assertEquals(3, wb.getNumberOfSheets()); + } + } + + @Test + void testFailOnXls() throws Exception { + final File file = HSSFTestDataSamples.getSampleFile("44010-SingleChart.xls"); + XSSFReadException xre = assertThrows(XSSFReadException.class, () -> XSSFParser.parse(file)); + assertInstanceOf(OLE2NotOfficeXmlFileException.class, xre.getCause()); + } +} diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hslf/HSLFReadException.java b/poi-scratchpad/src/main/java/org/apache/poi/hslf/HSLFReadException.java index 75312472ac..4411401873 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hslf/HSLFReadException.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hslf/HSLFReadException.java @@ -19,7 +19,8 @@ package org.apache.poi.hslf; import org.apache.poi.POIException; /** - * An exception that indicates a problem reading a ppt file. + * An exception that indicates a problem reading a ppt file. Usually, a more + * specific exception will be wrapped as the cause. *
This exception is only used by some new methods. * Historically, POI has used {@link RuntimeException} for most of its * exceptions, but this is not a good practice. This class is a checked diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hwpf/HWPFReadException.java b/poi-scratchpad/src/main/java/org/apache/poi/hwpf/HWPFReadException.java index ec3ce80bc4..f740d45b63 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hwpf/HWPFReadException.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hwpf/HWPFReadException.java @@ -19,7 +19,8 @@ package org.apache.poi.hwpf; import org.apache.poi.POIException; /** - * An exception that indicates a problem reading a doc file. + * An exception that indicates a problem reading a doc file. Usually, a more + * specific exception will be wrapped as the cause. *
This exception is only used by some new methods. * Historically, POI has used {@link RuntimeException} for most of its * exceptions, but this is not a good practice. This class is a checked diff --git a/poi/src/main/java/org/apache/poi/hssf/HSSFReadException.java b/poi/src/main/java/org/apache/poi/hssf/HSSFReadException.java index 1bc2ae207a..4f77a6a720 100644 --- a/poi/src/main/java/org/apache/poi/hssf/HSSFReadException.java +++ b/poi/src/main/java/org/apache/poi/hssf/HSSFReadException.java @@ -19,7 +19,8 @@ package org.apache.poi.hssf; import org.apache.poi.POIException; /** - * An exception that indicates a problem reading an xls file. + * An exception that indicates a problem reading an xls file. Usually, a more + * specific exception will be wrapped as the cause. *
This exception is only used by some new methods. * Historically, POI has used {@link RuntimeException} for most of its * exceptions, but this is not a good practice. This class is a checked diff --git a/test-data/spreadsheet/HeaderFooterComplexFormats.xlsx b/test-data/spreadsheet/HeaderFooterComplexFormats.xlsx index 337f425440..6dfc2040f5 100644 Binary files a/test-data/spreadsheet/HeaderFooterComplexFormats.xlsx and b/test-data/spreadsheet/HeaderFooterComplexFormats.xlsx differ