try {
ctSettings = SettingsDocument.Factory.parse(inputStream, DEFAULT_XML_OPTIONS).getSettings();
} catch (Exception e) {
- throw new RuntimeException(e);
+ throw new IllegalArgumentException("Failed to read data from input-stream", e);
}
}
if (recClass == WorksheetProtectionBlock.class) {
return getWorksheetProtectionBlockInsertPos(records);
}
- throw new RuntimeException("Unexpected record class (" + recClass.getName() + ")");
+ throw new IllegalArgumentException("Unexpected record class (" + recClass.getName() + ")");
}
/**
return i+1;
}
}
- throw new RuntimeException("Did not find insert point for GUTS");
+ throw new IllegalArgumentException("Did not find insert point for GUTS");
}
private static boolean isPageBreakPriorRecord(Object rb) {
if (rb instanceof Record) {
// DataValidityTable
}
}
- throw new RuntimeException("Did not find Window2 record");
+ throw new IllegalArgumentException("Did not find Window2 record");
}
private static int findInsertPosForNewMergedRecordTable(List<RecordBase> records) {
return i + 1;
}
}
- throw new RuntimeException("Did not find Window2 record");
+ throw new IllegalArgumentException("Did not find Window2 record");
}
// ConditionalFormattingTable
case HyperlinkRecord.sid:
case UnknownRecord.QUICKTIP_0800:
- // name of a VBA module
+ // name of a VBA module
case UnknownRecord.CODENAME_1BA:
return true;
}
}
}
// worksheet stream is seriously broken
- throw new RuntimeException("DimensionsRecord not found");
+ throw new IllegalArgumentException("DimensionsRecord not found");
}
private static int getGutsRecordInsertPos(List<RecordBase> records) {
return i+1;
}
}
- throw new RuntimeException("Did not find insert point for GUTS");
+ throw new IllegalArgumentException("Did not find insert point for GUTS");
}
private static boolean isGutsPriorRecord(RecordBase rb) {
return true;
case EOFRecord.sid:
// WINDOW2 should always be present, so shouldn't have got this far
- throw new RuntimeException("Found EOFRecord before WindowTwoRecord was encountered");
+ throw new IllegalArgumentException("Found EOFRecord before WindowTwoRecord was encountered");
}
return PageSettingsBlock.isComponentRecord(sid);
}
package org.apache.poi.hssf.model;
import java.util.List;
+import java.util.NoSuchElementException;
import org.apache.poi.hssf.record.Record;
/**
public Record getNext() {
if(!hasNext()) {
- throw new RuntimeException("Attempt to read past end of record stream");
+ throw new NoSuchElementException("Attempt to read past end of record stream");
}
_countRead ++;
return _list.get(_nextIndex++);
// records from a subsequent sheet. For example, if SharedFormulaRecords
// are taken from the wrong sheet, this could cause bug 44449.
if (!rs.hasNext()) {
- throw new RuntimeException("Failed to find end of row/cell records");
+ throw new IllegalStateException("Failed to find end of row/cell records");
}
Record rec = rs.getNext();
case MergeCellsRecord.sid: dest = mergeCellRecords; break;
case SharedFormulaRecord.sid: dest = shFrmRecords;
if (!(prevRec instanceof FormulaRecord)) {
- throw new RuntimeException("Shared formula record should follow a FormulaRecord");
+ throw new IllegalStateException("Shared formula record should follow a FormulaRecord, but had " + prevRec);
}
FormulaRecord fr = (FormulaRecord)prevRec;
firstCellRefs.add(new CellReference(fr.getRow(), fr.getColumn()));
field_6_reserved = 0;
break;
default:
- throw new RuntimeException("Unusual record size remaining=(" + in.remaining() + ")");
+ throw new IllegalArgumentException("Unusual record size remaining=(" + in.remaining() + ")");
}
}
// 5.38.3 'Add-In Functions'
_isAddInFunctions = true;
if(field_1_number_of_sheets != 1) {
- throw new RuntimeException("Expected 0x0001 for number of sheets field in 'Add-In Functions' but got ("
+ throw new IllegalArgumentException("Expected 0x0001 for number of sheets field in 'Add-In Functions' but got ("
+ field_1_number_of_sheets + ")");
}
} else {
- throw new RuntimeException("invalid EXTERNALBOOK code ("
+ throw new IllegalArgumentException("invalid EXTERNALBOOK code ("
+ Integer.toHexString(nextShort) + ")");
}
}
continue;
}
if (!(rec instanceof CellValueRecordInterface)) {
- throw new RuntimeException("Unexpected record type (" + rec.getClass().getName() + ")");
+ throw new IllegalArgumentException("Unexpected record type (" + rec.getClass().getName() + ")");
}
_valuesAgg.construct((CellValueRecordInterface)rec, rs, svm);
}
_valuesAgg.removeAllCellsValuesForRow(rowIndex);
RowRecord rr = _rowRecords.remove(rowIndex);
if (rr == null) {
- throw new RuntimeException("Invalid row index (" + rowIndex + ")");
+ throw new IllegalArgumentException("Invalid row index (" + rowIndex + ")");
}
if (row != rr) {
_rowRecords.put(rowIndex, rr);
- throw new RuntimeException("Attempt to remove row that does not belong to this sheet");
+ throw new IllegalArgumentException("Attempt to remove row that does not belong to this sheet");
}
// Clear the cached values
try {
return _rowRecordValues[startIndex].getRowNumber();
} catch(ArrayIndexOutOfBoundsException e) {
- throw new RuntimeException("Did not find start row for block " + block);
+ throw new IllegalArgumentException("Did not find start row for block " + block);
}
}
try {
return _rowRecordValues[endIndex].getRowNumber();
} catch(ArrayIndexOutOfBoundsException e) {
- throw new RuntimeException("Did not find end row for block " + block);
+ throw new IllegalArgumentException("Did not find end row for block " + block);
}
}
}
}
if (_numberOfFormulas >= _frAggs.length) {
- throw new RuntimeException("Too many formula records for shared formula group");
+ throw new IllegalStateException("Too many formula records for shared formula group: " + _numberOfFormulas +
+ ", expecting less than " + _frAggs.length);
}
_frAggs[_numberOfFormulas++] = agg;
}
public SharedFormulaRecord linkSharedFormulaRecord(CellReference firstCell, FormulaRecordAggregate agg) {
SharedFormulaGroup result = findFormulaGroupForCell(firstCell);
if(null == result) {
- throw new RuntimeException("Failed to find a matching shared formula record");
+ throw new IllegalArgumentException("Failed to find a matching shared formula record for cell: " + firstCell);
}
result.add(agg);
return result.getSFR();
private static int readUShortAndCheck(LittleEndianInput in) {
if (in.available() < ENCODED_SIZE) {
// Ran out of data
- throw new RuntimeException("Ran out of data reading CellRangeAddress");
+ throw new IllegalArgumentException("Ran out of data reading CellRangeAddress, available: " + in.available());
}
return in.readUShort();
}
protected StandardEncryptionVerifier(LittleEndianInput is, StandardEncryptionHeader header) {
int saltSize = is.readInt();
- if (saltSize!=16) {
- throw new RuntimeException("Salt size != 16 !?");
+ if (saltSize != 16) {
+ throw new IllegalArgumentException("Salt size != 16: " + saltSize);
}
byte[] salt = new byte[16];
throw new IllegalStateException("cannot perform requested operation on a closed stream");
}
if (requestedSize > _document_size - _current_offset) {
- throw new RuntimeException("Buffer underrun - requested " + requestedSize
+ throw new IllegalStateException("Buffer underrun - requested " + requestedSize
+ " bytes but " + (_document_size - _current_offset) + " was available");
}
}
@Override
public void readFully(byte[] buf, int off, int len) {
if (len < 0) {
- throw new RuntimeException("Can't read negative number of bytes");
+ throw new IllegalArgumentException("Can't read negative number of bytes, but had: " + len);
}
checkAvaliable(len);
in.readInt();
return ErrorConstant.valueOf(errCode);
}
- throw new RuntimeException("Unknown grbit value (" + grbit + ")");
+ throw new IllegalArgumentException("Unknown grbit value (" + grbit + ")");
}
private static Object readBoolean(LittleEndianInput in) {
return Boolean.TRUE;
}
// Don't tolerate unusual boolean encoded values (unless it becomes evident that they occur)
- throw new RuntimeException("unexpected boolean encoding (" + val + ")");
+ throw new IllegalArgumentException("unexpected boolean encoding (" + val + ")");
}
public static int getEncodedSize(Object[] values) {
temp.add(ptg);
}
if(pos != size) {
- throw new RuntimeException("Ptg array size mismatch");
+ throw new IllegalArgumentException("Ptg array size mismatch");
}
if (hasArrayPtgs) {
Ptg[] result = toPtgArray(temp);
case IntPtg.sid: return new IntPtg(in); // 0x1e
case NumberPtg.sid: return new NumberPtg(in); // 0x1f
}
- throw new RuntimeException("Unexpected base token id (" + id + ")");
+ throw new IllegalArgumentException("Unexpected base token id (" + id + ")");
}
private static Ptg[] toPtgArray(List<Ptg> l) {
public final void setClass(byte thePtgClass) {
if (isBaseToken()) {
- throw new RuntimeException("setClass should not be called on a base token");
+ throw new IllegalStateException("setClass should not be called on a base token");
}
ptgClass = thePtgClass;
}
case Ptg.CLASS_VALUE: return 'V';
case Ptg.CLASS_ARRAY: return 'A';
}
- throw new RuntimeException("Unknown operand class (" + ptgClass + ")");
+ throw new IllegalArgumentException("Unknown operand class (" + ptgClass + ")");
}
public abstract byte getDefaultOperandClass();
private static int readUShortAndCheck(RecordInputStream in) {
if (in.remaining() < ENCODED_SIZE) {
// Ran out of data
- throw new RuntimeException("Ran out of data reading CellRangeAddress");
+ throw new IllegalArgumentException("Ran out of data reading CellRangeAddress");
}
return in.readUShort();
}
protected void checkPosition(int i) {
if (i > count - pos) {
- throw new RuntimeException("Buffer overrun, having " + count + " bytes in the stream and position is at " + pos +
+ throw new IllegalStateException("Buffer overrun, having " + count + " bytes in the stream and position is at " + pos +
", but trying to increment position by " + i);
}
}
RuntimeException.class,
() -> new PropertySet(new DocumentInputStream(entry))
);
- assertEquals("Can't read negative number of bytes", ex.getMessage());
+ assertEquals("Can't read negative number of bytes, but had: -218103608", ex.getMessage());
}
}