pjfanning opened a new issue, #1556:
URL: https://github.com/apache/poi/issues/1556
Main code has 205 `assert` statements in 99 files. Assertions are off in
most runtimes, so these checks only run in tests, which the build runs with
`-ea`. In production, a failed check usually becomes a `NullPointerException`
or `ArrayIndexOutOfBoundsException` a few lines later, or wrong output. None of
the asserts have side effects, so turning assertions off only drops the checks.
Line numbers below are for trunk at 545dca7379. Counts are approximate.
### A. Data from files checked only by an assert (~25): replace with
`RecordFormatException` / `IllegalStateException`
When these checks fail, production already fails or reads at the wrong
offset, so throwing a clear exception changes no outcome.
- **EMF/EMF+:**
- an unknown type id gives null, then an NPE: `HemfPlusBrush:354`,
`HemfPlusImage:369,531`, `HemfPlusObject:175`, `HemfComment:271` (#1552 fixed
the same pattern in `HemfPlusRegion.readNode`)
- `HemfComment:276`: a negative skip count
- `HemfEmbeddedIterator:233,257,307`
- `HemfPlusRegion:324`
- **WMF:**
- `HwmfFill:988` (an unknown raster op gives null),
`HwmfTernaryRasterOp:445`
- `HwmfBitmap16:75,78`: a short skip on truncated data
- **HSLF:**
- `HSLFTable:208`: an index of -1 throws `ArrayIndexOutOfBoundsException`
- `HSLFTextParagraph:507`: unboxing a null `Short`
- `blip/EMF:71`, `blip/WMF:68`: a short skip, so the picture data is read
from the wrong offset
- `HSLFSlideShowEncrypted:568`
- **POIFS/crypto:** `POIFSMiniStore:74`, `CryptoAPIDecryptor:222`
- **OOXML:** `XSLFTable:429` (a `gridSpan` larger than the column count),
`XSSFPivotCacheDefinition:135`
### B. "MUST" values from the spec checked by an assert (~15): don't throw
Examples:
- `HemfPalette:77` (`version == 0x0300`)
- `HemfPlusDraw:373,383,521` (`srcUnit == Pixel`, `count == 3`)
- `HemfComment:185,240`, `HemfDraw:997`, `HemfMisc:628`
- `HwmfBitmapDib:240,242,257`
- `HemfPlusRecordIterator:88`
Parsing carries on when these fail today, so throwing would reject files
that currently render. Log them, or remove them. A value used later as an
index, like `penId` (0-63) at `HemfPlusDraw:207`, should be range-checked where
it's used.
### C. Caller arguments or unsupported calls (~6): replace with
`IllegalArgumentException` / `UnsupportedOperationException`
- `XSSFSheet.removeMergedRegion:1979` (index)
- `TextSpecInfoAtom.setParentSize:130` (size)
- `EscherColorRef:170` (length)
- `SprmUtils:90` (missing parameter)
- `HSLFSlideShowEncrypted.addEncryptionRecord:556` (null argument)
- `XSLFSlide.setNotes:387` is `@NotImplemented` and silently does nothing
### D. Internal invariants (~110): leave as asserts
- **Results of POI's own code:** values POI just created or computed, e.g.
`getDefaultSheetView(true) != null` (most of the 17 in `XSSFSheet`), the
results of `createSpContainer`, the `XWPFRun` underline, `SXSSFPicture` loop
bounds, the `Range` / `TextPieceTable` binary searches, `YearFracCalculator`,
`Index`.
- **`GenericRecordXmlWriter`:** its own internal state.
- **`PresetParser`:** it parses the preset shape XML bundled in the jar, so
the input is trusted.
### E. `hashCode()` stubs (18): implement real hash codes
`assert false : "hashCode not designed"; return 42;` in `FormatRun`,
`HSSFChildAnchor`, `HSSFClientAnchor`, `HSSFRichTextString`, `XSSFClientAnchor`
and 13 HWPF classes. With assertions off they return a constant, which is legal
but makes hash maps slow. With `-ea`, putting one in a `HashMap` throws. They
should hash the fields `equals` compares.
Suggested order, one PR per area: A for EMF/WMF together with B, then A for
HSLF, POIFS/crypto and OOXML, then C, then E.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]