diff --git a/poi/src/main/java/org/apache/poi/extractor/ExtractorFactory.java b/poi/src/main/java/org/apache/poi/extractor/ExtractorFactory.java index 42c4580f43..03a8278077 100644 --- a/poi/src/main/java/org/apache/poi/extractor/ExtractorFactory.java +++ b/poi/src/main/java/org/apache/poi/extractor/ExtractorFactory.java @@ -243,8 +243,9 @@ public final class ExtractorFactory { throw new IOException("Can't create extractor - unsupported file type: "+fm); } - POIFSFileSystem poifs = new POIFSFileSystem(file, true); + POIFSFileSystem poifs = null; try { + poifs = new POIFSFileSystem(file, true); DirectoryNode root = poifs.getRoot(); boolean isOOXML = root.hasEntry(DEFAULT_POIFS_ENTRY) || root.hasEntry(OOXML_PACKAGE); return wp(isOOXML ? FileMagic.OOXML : fm, w -> w.create(root, password)); diff --git a/poi/src/main/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java b/poi/src/main/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java index 9fcdf6c81e..e2504d2712 100644 --- a/poi/src/main/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java +++ b/poi/src/main/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java @@ -269,6 +269,8 @@ public final class HSSFWorkbook extends POIDocument implements Workbook { * preserve nodes set to true. * * @throws IOException if the stream cannot be read + * @throws RuntimeException a number of runtime exceptions can be thrown, especially if there are problems with the + * input format * @see #HSSFWorkbook(POIFSFileSystem, boolean) * @see POIFSFileSystem */ @@ -286,6 +288,8 @@ public final class HSSFWorkbook extends POIDocument implements Workbook { * need to. If set, will store all of the POIFSFileSystem * in memory * @throws IOException if the stream cannot be read + * @throws RuntimeException a number of runtime exceptions can be thrown, especially if there are problems with the + * input format * @see POIFSFileSystem */ public HSSFWorkbook(POIFSFileSystem fs, boolean preserveNodes) @@ -333,6 +337,8 @@ public final class HSSFWorkbook extends POIDocument implements Workbook { * need to. If set, will store all of the POIFSFileSystem * in memory * @throws IOException if the stream cannot be read + * @throws RuntimeException a number of runtime exceptions can be thrown, especially if there are problems with the + * input format * @see POIFSFileSystem */ public HSSFWorkbook(DirectoryNode directory, POIFSFileSystem fs, boolean preserveNodes) @@ -351,6 +357,8 @@ public final class HSSFWorkbook extends POIDocument implements Workbook { * need to. If set, will store all of the POIFSFileSystem * in memory * @throws IOException if the stream cannot be read + * @throws RuntimeException a number of runtime exceptions can be thrown, especially if there are problems with the + * input format * @see POIFSFileSystem */ public HSSFWorkbook(DirectoryNode directory, boolean preserveNodes) @@ -406,6 +414,8 @@ public final class HSSFWorkbook extends POIDocument implements Workbook { * preserve nodes set to true. * * @throws IOException if the stream cannot be read + * @throws RuntimeException a number of runtime exceptions can be thrown, especially if there are problems with the + * input format * @see #HSSFWorkbook(InputStream, boolean) * @see #HSSFWorkbook(POIFSFileSystem) * @see POIFSFileSystem @@ -423,6 +433,8 @@ public final class HSSFWorkbook extends POIDocument implements Workbook { * macros. This takes more memory, so only say yes if you * need to. * @throws IOException if the stream cannot be read + * @throws RuntimeException a number of runtime exceptions can be thrown, especially if there are problems with the + * input format * @see POIFSFileSystem * @see #HSSFWorkbook(POIFSFileSystem) */ diff --git a/poi/src/main/java/org/apache/poi/ss/usermodel/WorkbookFactory.java b/poi/src/main/java/org/apache/poi/ss/usermodel/WorkbookFactory.java index 003b7311a8..838b82218d 100644 --- a/poi/src/main/java/org/apache/poi/ss/usermodel/WorkbookFactory.java +++ b/poi/src/main/java/org/apache/poi/ss/usermodel/WorkbookFactory.java @@ -67,6 +67,8 @@ public final class WorkbookFactory { * @return The created workbook * * @throws IOException if an error occurs while creating the objects + * @throws RuntimeException a number of other runtime exceptions can be thrown, especially if there are problems with the + * input format */ public static Workbook create(boolean xssf) throws IOException { return wp(xssf ? FileMagic.OOXML : FileMagic.OLE2, WorkbookProvider::create); @@ -83,6 +85,8 @@ public final class WorkbookFactory { * @return The created workbook * * @throws IOException if an error occurs while reading the data + * @throws RuntimeException a number of runtime exceptions can be thrown, especially if there are problems with the + * input format */ public static Workbook create(POIFSFileSystem fs) throws IOException { return create(fs, null); @@ -101,6 +105,8 @@ public final class WorkbookFactory { * @return The created Workbook * * @throws IOException if an error occurs while reading the data + * @throws RuntimeException a number of runtime exceptions can be thrown, especially if there are problems with the + * input format */ private static Workbook create(final POIFSFileSystem fs, String password) throws IOException { return create(fs.getRoot(), password); @@ -118,6 +124,8 @@ public final class WorkbookFactory { * @return The created Workbook * * @throws IOException if an error occurs while reading the data + * @throws RuntimeException a number of other exceptions can be thrown, especially if there are problems with the + * input format */ public static Workbook create(final DirectoryNode root) throws IOException { return create(root, null); @@ -137,6 +145,8 @@ public final class WorkbookFactory { * @return The created Workbook * * @throws IOException if an error occurs while reading the data + * @throws RuntimeException a number of runtime exceptions can be thrown, especially if there are problems with the + * input format */ public static Workbook create(final DirectoryNode root, String password) throws IOException { // Encrypted OOXML files go inside OLE2 containers, is this one? @@ -168,6 +178,8 @@ public final class WorkbookFactory { * @throws IOException if an error occurs while reading the data * @throws EncryptedDocumentException If the Workbook given is password protected * @throws EmptyFileException If the given data is empty + * @throws RuntimeException a number of other runtime exceptions can be thrown, especially if there are problems with the + * input format */ public static Workbook create(InputStream inp) throws IOException, EncryptedDocumentException { return create(inp, null); @@ -195,6 +207,8 @@ public final class WorkbookFactory { * @throws IOException if an error occurs while reading the data * @throws EncryptedDocumentException If the wrong password is given for a protected file * @throws EmptyFileException If the given data is empty + * @throws RuntimeException a number of other runtime exceptions can be thrown, especially if there are problems with the + * input format */ public static Workbook create(InputStream inp, String password) throws IOException, EncryptedDocumentException { InputStream is = FileMagic.prepareToCheckMagic(inp); @@ -234,6 +248,8 @@ public final class WorkbookFactory { * @throws IOException if an error occurs while reading the data * @throws EncryptedDocumentException If the Workbook given is password protected * @throws EmptyFileException If the given data is empty + * @throws RuntimeException a number of other runtime exceptions can be thrown, especially if there are problems with the + * input format */ public static Workbook create(File file) throws IOException, EncryptedDocumentException { return create(file, null); @@ -254,6 +270,8 @@ public final class WorkbookFactory { * @throws IOException if an error occurs while reading the data * @throws EncryptedDocumentException If the wrong password is given for a protected file * @throws EmptyFileException If the given data is empty + * @throws RuntimeException a number of other runtime exceptions can be thrown, especially if there are problems with the + * input format */ public static Workbook create(File file, String password) throws IOException, EncryptedDocumentException { return create(file, password, false); @@ -276,6 +294,8 @@ public final class WorkbookFactory { * @throws IOException if an error occurs while reading the data * @throws EncryptedDocumentException If the wrong password is given for a protected file * @throws EmptyFileException If the given data is empty + * @throws RuntimeException a number of other runtime exceptions can be thrown, especially if there are problems with the + * input format */ public static Workbook create(File file, String password, boolean readOnly) throws IOException, EncryptedDocumentException { if (!file.exists()) {