This is an automated email from the ASF dual-hosted git repository. centic pushed a commit to branch trunk in repository https://gitbox.apache.org/repos/asf/poi.git
commit ddf71d0984e3a3d62f7287908e9ae19862c88d8f Author: Dominik Stadler <[email protected]> AuthorDate: Tue Jan 6 20:29:33 2026 +0100 Avoid two NPEs which were currently "expected" in tests When things go wrong, we always want to give an explanation via an exception instead of an NPE. --- .../record/aggregates/FormulaRecordAggregate.java | 5 ++++- .../org/apache/poi/hssf/usermodel/HSSFComment.java | 6 +++++- test-data/spreadsheet/stress.xls | Bin 73728 -> 73216 bytes 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/poi/src/main/java/org/apache/poi/hssf/record/aggregates/FormulaRecordAggregate.java b/poi/src/main/java/org/apache/poi/hssf/record/aggregates/FormulaRecordAggregate.java index 5ce1f62f68..f8fd855050 100644 --- a/poi/src/main/java/org/apache/poi/hssf/record/aggregates/FormulaRecordAggregate.java +++ b/poi/src/main/java/org/apache/poi/hssf/record/aggregates/FormulaRecordAggregate.java @@ -39,7 +39,7 @@ import org.apache.poi.util.RecordFormatException; public final class FormulaRecordAggregate extends RecordAggregate implements CellValueRecordInterface { private final FormulaRecord _formulaRecord; - private SharedValueManager _sharedValueManager; + private final SharedValueManager _sharedValueManager; /** caches the calculated result of the formula */ private StringRecord _stringRecord; private SharedFormulaRecord _sharedFormulaRecord; @@ -195,6 +195,9 @@ public final class FormulaRecordAggregate extends RecordAggregate implements Cel CellReference expRef = _formulaRecord.getFormula().getExpReference(); if (expRef != null) { ArrayRecord arec = _sharedValueManager.getArrayRecord(expRef.getRow(), expRef.getCol()); + if (arec == null) { + throw new IllegalStateException("Could not get ArrayRecord for cell-reference " + expRef.formatAsString()); + } return arec.getFormulaTokens(); } return _formulaRecord.getParsedExpression(); diff --git a/poi/src/main/java/org/apache/poi/hssf/usermodel/HSSFComment.java b/poi/src/main/java/org/apache/poi/hssf/usermodel/HSSFComment.java index af6ac8b4f2..fabfcaa33c 100644 --- a/poi/src/main/java/org/apache/poi/hssf/usermodel/HSSFComment.java +++ b/poi/src/main/java/org/apache/poi/hssf/usermodel/HSSFComment.java @@ -285,7 +285,11 @@ public class HSSFComment extends HSSFTextbox implements Comment { byte [] inSp = getEscherContainer().serialize(); spContainer.fillFields(inSp, 0, new DefaultEscherRecordFactory()); ObjRecord obj = (ObjRecord) getObjRecord().cloneViaReserialise(); - NoteRecord note = (NoteRecord) getNoteRecord().cloneViaReserialise(); + NoteRecord noteRecord = getNoteRecord(); + if (noteRecord == null) { + throw new IllegalStateException("Could not clone the note record for this comment because it is null"); + } + NoteRecord note = (NoteRecord) noteRecord.cloneViaReserialise(); return new HSSFComment(spContainer, obj, txo, note); } diff --git a/test-data/spreadsheet/stress.xls b/test-data/spreadsheet/stress.xls index aa42d4cdc8..a3a5a5694a 100644 Binary files a/test-data/spreadsheet/stress.xls and b/test-data/spreadsheet/stress.xls differ --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
