mirror of https://github.com/apache/poi.git
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
This commit is contained in:
parent
6b1e23665d
commit
f71833e1d9
|
@ -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"));
|
||||
}
|
||||
}
|
|
@ -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
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Binary file not shown.
Loading…
Reference in New Issue