This is an automated email from the ASF dual-hosted git repository.
fanningpj pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/poi.git
The following commit(s) were added to refs/heads/trunk by this push:
new 9f9ff14e56 add test
9f9ff14e56 is described below
commit 9f9ff14e56f98ac48d37c993b34793e7d0dd7cf0
Author: PJ Fanning <[email protected]>
AuthorDate: Thu Aug 28 13:00:54 2025 +0100
add test
---
.../org/apache/poi/xslf/XSLFReadException.java | 3 +-
.../org/apache/poi/xssf/XSSFReadException.java | 3 +-
.../org/apache/poi/xwpf/XWPFReadException.java | 3 +-
.../java/org/apache/poi/xssf/TestXSSFParser.java | 47 +++++++++++++++++++++
.../org/apache/poi/hslf/HSLFReadException.java | 3 +-
.../org/apache/poi/hwpf/HWPFReadException.java | 3 +-
.../org/apache/poi/hssf/HSSFReadException.java | 3 +-
.../spreadsheet/HeaderFooterComplexFormats.xlsx | Bin 9543 -> 7513 bytes
8 files changed, 59 insertions(+), 6 deletions(-)
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.
* <p>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.
* <p>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.
* <p>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.
* <p>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.
* <p>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.
* <p>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
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]