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.
This commit is contained in:
Dominik Stadler 2026-01-06 20:29:33 +01:00
parent fb75600872
commit ddf71d0984
3 changed files with 9 additions and 2 deletions

View File

@ -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();

View File

@ -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);
}

Binary file not shown.