aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDominik Stadler <centic@apache.org>2021-04-26 15:12:32 +0000
committerDominik Stadler <centic@apache.org>2021-04-26 15:12:32 +0000
commitf71833e1d9696710c09dc4b5ca13da1a9a2b2e80 (patch)
tree38252c493f9a7f0c733a204aefe06483904fe29e
parent6b1e23665d413068d0cdb47b97d8f93a467ec0d0 (diff)
downloadpoi-f71833e1d9696710c09dc4b5ca13da1a9a2b2e80.tar.gz
poi-f71833e1d9696710c09dc4b5ca13da1a9a2b2e80.zip
Do not return null for POITextExtractor.getMetadataTextExtractor() for old Excel files
To adhere to the JavaDoc of the POITextExtractor interface which does not document a possible null return. git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1889205 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--poi-integration/src/test/java/org/apache/poi/stress/HSSFFileHandler.java4
-rw-r--r--poi/src/main/java/org/apache/poi/hssf/extractor/OldExcelExtractor.java33
-rw-r--r--poi/src/test/java/org/apache/poi/hssf/extractor/TestOldExcelExtractor.java21
-rw-r--r--test-data/spreadsheet/stress.xlsbin51712 -> 36864 bytes
4 files changed, 55 insertions, 3 deletions
diff --git a/poi-integration/src/test/java/org/apache/poi/stress/HSSFFileHandler.java b/poi-integration/src/test/java/org/apache/poi/stress/HSSFFileHandler.java
index 9ee54b4790..1e0348cac5 100644
--- a/poi-integration/src/test/java/org/apache/poi/stress/HSSFFileHandler.java
+++ b/poi-integration/src/test/java/org/apache/poi/stress/HSSFFileHandler.java
@@ -107,7 +107,7 @@ class HSSFFileHandler extends SpreadsheetHandler {
// a test-case to test this locally without executing the full TestAllFiles
@Test
void test() throws Exception {
- File file = new File("test-data/spreadsheet/49219.xls");
+ File file = new File("../test-data/spreadsheet/59074.xls");
try (InputStream stream = new FileInputStream(file)) {
handleFile(stream, file.getPath());
@@ -122,6 +122,6 @@ class HSSFFileHandler extends SpreadsheetHandler {
@Test
@SuppressWarnings("java:S2699")
void testExtractor() throws Exception {
- handleExtracting(new File("test-data/spreadsheet/BOOK_in_capitals.xls"));
+ handleExtracting(new File("../test-data/spreadsheet/59074.xls"));
}
} \ No newline at end of file
diff --git a/poi/src/main/java/org/apache/poi/hssf/extractor/OldExcelExtractor.java b/poi/src/main/java/org/apache/poi/hssf/extractor/OldExcelExtractor.java
index e6a55f88ff..d5ef5142e7 100644
--- a/poi/src/main/java/org/apache/poi/hssf/extractor/OldExcelExtractor.java
+++ b/poi/src/main/java/org/apache/poi/hssf/extractor/OldExcelExtractor.java
@@ -316,7 +316,38 @@ public class OldExcelExtractor implements POITextExtractor {
@Override
public POITextExtractor getMetadataTextExtractor() {
- return null;
+ return new POITextExtractor() {
+
+ @Override
+ public String getText() {
+ return "";
+ }
+
+ @Override
+ public POITextExtractor getMetadataTextExtractor() {
+ throw new IllegalStateException("You already have the Metadata Text Extractor, not recursing!");
+ }
+
+ @Override
+ public void setCloseFilesystem(boolean doCloseFilesystem) {
+
+ }
+
+ @Override
+ public boolean isCloseFilesystem() {
+ return toClose != null;
+ }
+
+ @Override
+ public Closeable getFilesystem() {
+ return toClose;
+ }
+
+ @Override
+ public Object getDocument() {
+ return ris;
+ }
+ };
}
@Override
diff --git a/poi/src/test/java/org/apache/poi/hssf/extractor/TestOldExcelExtractor.java b/poi/src/test/java/org/apache/poi/hssf/extractor/TestOldExcelExtractor.java
index 3fb037c93e..7dbabe14b1 100644
--- a/poi/src/test/java/org/apache/poi/hssf/extractor/TestOldExcelExtractor.java
+++ b/poi/src/test/java/org/apache/poi/hssf/extractor/TestOldExcelExtractor.java
@@ -35,6 +35,7 @@ import java.security.Permission;
import org.apache.poi.EmptyFileException;
import org.apache.poi.EncryptedDocumentException;
import org.apache.poi.POIDataSamples;
+import org.apache.poi.extractor.POITextExtractor;
import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.poifs.filesystem.OfficeXmlFileException;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
@@ -378,4 +379,24 @@ final class TestOldExcelExtractor {
this.status = status;
}
}
+
+ @Test
+ void testMetaData() throws IOException {
+ try (OldExcelExtractor extractor = createExtractor("testEXCEL_3.xls")) {
+ POITextExtractor metaData = extractor.getMetadataTextExtractor();
+ assertNotNull(metaData);
+
+ assertThrows(IllegalStateException.class, metaData::getMetadataTextExtractor);
+ assertEquals("", metaData.getText());
+ assertNotNull(metaData.getDocument());
+ assertTrue(metaData.isCloseFilesystem());
+ assertNotNull(metaData.getFilesystem());
+
+ // the setter is a NOP
+ metaData.setCloseFilesystem(false);
+ assertTrue(metaData.isCloseFilesystem());
+
+ metaData.close();
+ }
+ }
}
diff --git a/test-data/spreadsheet/stress.xls b/test-data/spreadsheet/stress.xls
index b613a89751..c773b819d5 100644
--- a/test-data/spreadsheet/stress.xls
+++ b/test-data/spreadsheet/stress.xls
Binary files differ