diff options
author | PJ Fanning <fanningpj@apache.org> | 2023-02-14 14:51:27 +0000 |
---|---|---|
committer | PJ Fanning <fanningpj@apache.org> | 2023-02-14 14:51:27 +0000 |
commit | 3968e289e4a746a4c1e8d27259afd6e735b9574a (patch) | |
tree | 4f7530103e8bdf8074593c8c0a08f236f6af0ae0 | |
parent | 3a70d5e0023c7e9a9f2d6d118c78ad6b345f3bd3 (diff) | |
download | poi-3968e289e4a746a4c1e8d27259afd6e735b9574a.tar.gz poi-3968e289e4a746a4c1e8d27259afd6e735b9574a.zip |
fix up use of ExceptionUtil in main poi-scratchpad module
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1907652 13f79535-47bb-0310-9956-ffa450edef68
14 files changed, 78 insertions, 8 deletions
diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hdgf/chunks/Chunk.java b/poi-scratchpad/src/main/java/org/apache/poi/hdgf/chunks/Chunk.java index b85592f112..b2a6b3925c 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hdgf/chunks/Chunk.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hdgf/chunks/Chunk.java @@ -22,6 +22,7 @@ import java.util.ArrayList; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.apache.poi.hdgf.chunks.ChunkFactory.CommandDefinition; +import org.apache.poi.util.ExceptionUtil; import org.apache.poi.util.LittleEndian; import static org.apache.logging.log4j.util.Unbox.box; @@ -245,6 +246,9 @@ public final class Chunk { } } catch (Exception e) { + if (ExceptionUtil.isFatal(e)) { + ExceptionUtil.rethrow(e); + } LOG.atError().withThrowable(e).log("Unexpected error processing command, ignoring and continuing. Command: {}", command); } diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hdgf/streams/ChunkStream.java b/poi-scratchpad/src/main/java/org/apache/poi/hdgf/streams/ChunkStream.java index b1c10ae3e7..9d807d7ed0 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hdgf/streams/ChunkStream.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hdgf/streams/ChunkStream.java @@ -25,6 +25,7 @@ import org.apache.poi.hdgf.chunks.Chunk; import org.apache.poi.hdgf.chunks.ChunkFactory; import org.apache.poi.hdgf.chunks.ChunkHeader; import org.apache.poi.hdgf.pointers.Pointer; +import org.apache.poi.util.ExceptionUtil; import static org.apache.logging.log4j.util.Unbox.box; @@ -72,9 +73,10 @@ public final class ChunkStream extends Stream { pos = contents.length; } } - } - catch (Exception e) - { + } catch (Exception e) { + if (ExceptionUtil.isFatal(e)) { + ExceptionUtil.rethrow(e); + } LOG.atError().withThrowable(e).log("Failed to create chunk at {}, ignoring rest of data.", box(pos)); } diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hemf/draw/HemfGraphics.java b/poi-scratchpad/src/main/java/org/apache/poi/hemf/draw/HemfGraphics.java index 113f8ede25..ac3e5772db 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hemf/draw/HemfGraphics.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hemf/draw/HemfGraphics.java @@ -51,6 +51,7 @@ import org.apache.poi.hwmf.record.HwmfColorRef; import org.apache.poi.hwmf.record.HwmfMisc; import org.apache.poi.hwmf.record.HwmfObjectTableEntry; import org.apache.poi.hwmf.record.HwmfPenStyle; +import org.apache.poi.util.ExceptionUtil; import org.apache.poi.util.Internal; public class HemfGraphics extends HwmfGraphics { @@ -145,6 +146,9 @@ public class HemfGraphics extends HwmfGraphics { try { pathConsumer.accept(path); } catch (Exception e) { + if (ExceptionUtil.isFatal(e)) { + ExceptionUtil.rethrow(e); + } // workaround if a path has been started and no MoveTo command // has been specified before the first lineTo/splineTo final Point2D loc = prop.getLocation(); diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hemf/record/emfplus/HemfPlusImage.java b/poi-scratchpad/src/main/java/org/apache/poi/hemf/record/emfplus/HemfPlusImage.java index 6afb53cdd3..c50a3fec34 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hemf/record/emfplus/HemfPlusImage.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hemf/record/emfplus/HemfPlusImage.java @@ -45,6 +45,7 @@ import org.apache.poi.sl.draw.ImageRenderer; import org.apache.poi.sl.usermodel.PictureData.PictureType; import org.apache.poi.util.BitField; import org.apache.poi.util.BitFieldFactory; +import org.apache.poi.util.ExceptionUtil; import org.apache.poi.util.GenericRecordJsonWriter; import org.apache.poi.util.GenericRecordUtil; import org.apache.poi.util.IOUtils; @@ -442,7 +443,10 @@ public class HemfPlusImage { default: break; } - } catch (Exception ignored) { + } catch (Exception e) { + if (ExceptionUtil.isFatal(e)) { + ExceptionUtil.rethrow(e); + } } return new Rectangle2D.Double(1,1,1,1); } diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hslf/blip/PICT.java b/poi-scratchpad/src/main/java/org/apache/poi/hslf/blip/PICT.java index 3e5042af46..172468a03f 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hslf/blip/PICT.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hslf/blip/PICT.java @@ -35,6 +35,7 @@ import org.apache.poi.ddf.EscherContainerRecord; import org.apache.poi.hslf.exceptions.HSLFException; import org.apache.poi.hslf.usermodel.HSLFSlideShow; import org.apache.poi.sl.image.ImageHeaderPICT; +import org.apache.poi.util.ExceptionUtil; import org.apache.poi.util.IOUtils; import org.apache.poi.util.Internal; import org.apache.poi.util.Removal; @@ -104,6 +105,9 @@ public final class PICT extends Metafile { Arrays.fill(chunk, (byte) 0); } } catch (Exception e) { + if (ExceptionUtil.isFatal(e)) { + ExceptionUtil.rethrow(e); + } int lastLen = chunk.length - 1; while (lastLen >= 0 && chunk[lastLen] == 0) { lastLen--; diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/MasterTextPropAtom.java b/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/MasterTextPropAtom.java index a6065e3e24..ff5305cce6 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/MasterTextPropAtom.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/MasterTextPropAtom.java @@ -27,6 +27,7 @@ import java.util.Map; import java.util.function.Supplier; import org.apache.poi.hslf.model.textproperties.IndentProp; +import org.apache.poi.util.ExceptionUtil; import org.apache.poi.util.GenericRecordUtil; import org.apache.poi.util.IOUtils; import org.apache.poi.util.LittleEndian; @@ -97,7 +98,10 @@ public final class MasterTextPropAtom extends RecordAtom { try { read(); - } catch (Exception e){ + } catch (Exception e) { + if (ExceptionUtil.isFatal(e)) { + ExceptionUtil.rethrow(e); + } LOG.atError().withThrowable(e).log("Failed to parse MasterTextPropAtom"); } } diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/TxMasterStyleAtom.java b/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/TxMasterStyleAtom.java index ca94a6acfd..af307cc102 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/TxMasterStyleAtom.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/TxMasterStyleAtom.java @@ -32,6 +32,7 @@ import org.apache.poi.hslf.exceptions.HSLFException; import org.apache.poi.hslf.model.textproperties.TextPropCollection; import org.apache.poi.hslf.model.textproperties.TextPropCollection.TextPropType; import org.apache.poi.sl.usermodel.TextShape.TextPlaceholder; +import org.apache.poi.util.ExceptionUtil; import org.apache.poi.util.GenericRecordUtil; import org.apache.poi.util.IOUtils; import org.apache.poi.util.LittleEndian; @@ -76,7 +77,10 @@ public final class TxMasterStyleAtom extends RecordAtom { //read available styles try { init(); - } catch (Exception e){ + } catch (Exception e) { + if (ExceptionUtil.isFatal(e)) { + ExceptionUtil.rethrow(e); + } LOG.atWarn().withThrowable(e).log("Exception when reading available styles"); } } diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hslf/usermodel/HSLFSlideShowEncrypted.java b/poi-scratchpad/src/main/java/org/apache/poi/hslf/usermodel/HSLFSlideShowEncrypted.java index 8c7effc7f3..04ea654546 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hslf/usermodel/HSLFSlideShowEncrypted.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hslf/usermodel/HSLFSlideShowEncrypted.java @@ -42,6 +42,7 @@ import org.apache.poi.poifs.crypt.Decryptor; import org.apache.poi.poifs.crypt.EncryptionInfo; import org.apache.poi.poifs.crypt.Encryptor; import org.apache.poi.util.BitField; +import org.apache.poi.util.ExceptionUtil; import org.apache.poi.util.IOUtils; import org.apache.poi.util.Internal; import org.apache.poi.util.LittleEndian; @@ -170,6 +171,9 @@ public class HSLFSlideShowEncrypted implements Closeable { } cyos.initCipherForBlock(persistId, false); } catch (Exception e) { + if (ExceptionUtil.isFatal(e)) { + ExceptionUtil.rethrow(e); + } throw new EncryptedPowerPointFileException(e); } return cyos; @@ -199,6 +203,9 @@ public class HSLFSlideShowEncrypted implements Closeable { readFully(ccis, docstream, offset+8, rlen); } catch (Exception e) { + if (ExceptionUtil.isFatal(e)) { + ExceptionUtil.rethrow(e); + } throw new EncryptedPowerPointFileException(e); } } @@ -283,6 +290,9 @@ public class HSLFSlideShowEncrypted implements Closeable { int blipLen = endOffset - offset; decryptPicBytes(pictstream, offset, blipLen); } catch (Exception e) { + if (ExceptionUtil.isFatal(e)) { + ExceptionUtil.rethrow(e); + } throw new CorruptPowerPointFileException(e); } } @@ -362,6 +372,9 @@ public class HSLFSlideShowEncrypted implements Closeable { ccos.write(pictstream, offset, blipLen); ccos.flush(); } catch (Exception e) { + if (ExceptionUtil.isFatal(e)) { + ExceptionUtil.rethrow(e); + } throw new EncryptedPowerPointFileException(e); } finally { IOUtils.closeQuietly(ccos); diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hwmf/usermodel/HwmfPicture.java b/poi-scratchpad/src/main/java/org/apache/poi/hwmf/usermodel/HwmfPicture.java index da220c941e..bbe782cd36 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hwmf/usermodel/HwmfPicture.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hwmf/usermodel/HwmfPicture.java @@ -47,6 +47,7 @@ import org.apache.poi.hwmf.record.HwmfRecordType; import org.apache.poi.hwmf.record.HwmfWindowing.WmfSetWindowExt; import org.apache.poi.hwmf.record.HwmfWindowing.WmfSetWindowOrg; import org.apache.poi.util.Dimension2DDouble; +import org.apache.poi.util.ExceptionUtil; import org.apache.poi.util.IOUtils; import org.apache.poi.util.LittleEndianInputStream; import org.apache.poi.util.LocaleUtil; @@ -106,6 +107,9 @@ public class HwmfPicture implements Iterable<HwmfRecord>, GenericRecord { recordSize = (int)recordSizeLong; recordFunction = leis.readShort(); } catch (Exception e) { + if (ExceptionUtil.isFatal(e)) { + ExceptionUtil.rethrow(e); + } LOG.atError().log("unexpected eof - wmf file was truncated"); break; } diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hwpf/HWPFDocument.java b/poi-scratchpad/src/main/java/org/apache/poi/hwpf/HWPFDocument.java index 5a4296f8e1..8dbd2e2fe9 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hwpf/HWPFDocument.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hwpf/HWPFDocument.java @@ -71,6 +71,7 @@ import org.apache.poi.poifs.filesystem.DirectoryNode; import org.apache.poi.poifs.filesystem.Entry; import org.apache.poi.poifs.filesystem.EntryUtils; import org.apache.poi.poifs.filesystem.POIFSFileSystem; +import org.apache.poi.util.ExceptionUtil; import org.apache.poi.util.IOUtils; import org.apache.poi.util.Internal; import org.apache.poi.util.LittleEndianByteArrayOutputStream; @@ -298,7 +299,9 @@ public final class HWPFDocument extends HWPFDocumentCore { try { preserveBinTables = Boolean.parseBoolean(System.getProperty(PROPERTY_PRESERVE_BIN_TABLES)); } catch (Exception exc) { - // ignore; + if (ExceptionUtil.isFatal(exc)) { + ExceptionUtil.rethrow(exc); + } } if (!preserveBinTables) { @@ -314,7 +317,9 @@ public final class HWPFDocument extends HWPFDocumentCore { try { preserveTextTable = Boolean.parseBoolean(System.getProperty(PROPERTY_PRESERVE_TEXT_TABLE)); } catch (Exception exc) { - // ignore; + if (ExceptionUtil.isFatal(exc)) { + ExceptionUtil.rethrow(exc); + } } if (!preserveTextTable) { _cft = new ComplexFileTable(); diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hwpf/converter/AbstractWordConverter.java b/poi-scratchpad/src/main/java/org/apache/poi/hwpf/converter/AbstractWordConverter.java index d6f410d286..0a25404bcf 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hwpf/converter/AbstractWordConverter.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hwpf/converter/AbstractWordConverter.java @@ -51,6 +51,7 @@ import org.apache.poi.hwpf.usermodel.TableCell; import org.apache.poi.hwpf.usermodel.TableRow; import org.apache.poi.poifs.filesystem.Entry; import org.apache.poi.util.Beta; +import org.apache.poi.util.ExceptionUtil; import org.apache.poi.util.Internal; import org.apache.poi.util.LocaleUtil; import org.apache.poi.util.StringUtil; @@ -627,6 +628,9 @@ public abstract class AbstractWordConverter { processDocumentInformation(summaryInformation); } } catch (Exception exc) { + if (ExceptionUtil.isFatal(exc)) { + ExceptionUtil.rethrow(exc); + } LOG.atWarn().withThrowable(exc).log("Unable to process document summary information"); } @@ -892,6 +896,9 @@ public abstract class AbstractWordConverter { try { return processOle2(doc, block, entry); } catch (Exception exc) { + if (ExceptionUtil.isFatal(exc)) { + ExceptionUtil.rethrow(exc); + } LOG.atWarn().withThrowable(exc).log("Unable to convert internal OLE2 object '{}'", box(characterRun.getPicOffset())); return false; } @@ -947,6 +954,9 @@ public abstract class AbstractWordConverter { processParagraph(wordDocument, flow, currentTableLevel, paragraph, label); processed = true; } catch (Exception exc) { + if (ExceptionUtil.isFatal(exc)) { + ExceptionUtil.rethrow(exc); + } LOG.atWarn().withThrowable(exc).log("Can't process paragraph as list entry, will be processed without list information"); } } diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hwpf/extractor/Word6Extractor.java b/poi-scratchpad/src/main/java/org/apache/poi/hwpf/extractor/Word6Extractor.java index 6334855763..19e538e511 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hwpf/extractor/Word6Extractor.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hwpf/extractor/Word6Extractor.java @@ -26,6 +26,7 @@ import org.apache.poi.hwpf.converter.WordToTextConverter; import org.apache.poi.hwpf.usermodel.Range; import org.apache.poi.poifs.filesystem.DirectoryNode; import org.apache.poi.poifs.filesystem.POIFSFileSystem; +import org.apache.poi.util.ExceptionUtil; /** * Class to extract the text from old (Word 6 / Word 95) Word Documents. @@ -90,6 +91,9 @@ public final class Word6Extractor implements POIOLE2TextExtractor { ret = WordExtractor.getParagraphText(r); } catch (Exception e) { + if (ExceptionUtil.isFatal(e)) { + ExceptionUtil.rethrow(e); + } // Something's up with turning the text pieces into paragraphs // Fall back to ripping out the text pieces ret = new String[doc.getTextTable().getTextPieces().size()]; diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hwpf/model/PicturesTable.java b/poi-scratchpad/src/main/java/org/apache/poi/hwpf/model/PicturesTable.java index 45e726e564..a52def67b3 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hwpf/model/PicturesTable.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hwpf/model/PicturesTable.java @@ -35,6 +35,7 @@ import org.apache.poi.hwpf.HWPFDocument; import org.apache.poi.hwpf.usermodel.CharacterRun; import org.apache.poi.hwpf.usermodel.Picture; import org.apache.poi.hwpf.usermodel.Range; +import org.apache.poi.util.ExceptionUtil; import org.apache.poi.util.Internal; import org.apache.poi.util.LittleEndian; @@ -179,6 +180,9 @@ public final class PicturesTable { pictures.add(new Picture(blip)); } } catch (Exception exc) { + if (ExceptionUtil.isFatal(exc)) { + ExceptionUtil.rethrow(exc); + } LOG.atWarn().withThrowable(exc).log("Unable to load picture from BLIP record at offset #{}", box(bse.getOffset())); } } diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hwpf/sprm/SprmBuffer.java b/poi-scratchpad/src/main/java/org/apache/poi/hwpf/sprm/SprmBuffer.java index 38a0efaa02..a77df8792a 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hwpf/sprm/SprmBuffer.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hwpf/sprm/SprmBuffer.java @@ -20,6 +20,7 @@ package org.apache.poi.hwpf.sprm; import java.util.Arrays; import org.apache.poi.common.Duplicatable; +import org.apache.poi.util.ExceptionUtil; import org.apache.poi.util.IOUtils; import org.apache.poi.util.Internal; import org.apache.poi.util.LittleEndian; @@ -208,6 +209,9 @@ public final class SprmBuffer implements Duplicatable { try { stringBuilder.append(iterator.next()); } catch (Exception exc) { + if (ExceptionUtil.isFatal(exc)) { + ExceptionUtil.rethrow(exc); + } stringBuilder.append("error"); } stringBuilder.append("; "); |