mirror of https://github.com/apache/poi.git
Fix from Florian Hopf from bug #54564 - Fix error message text
for a workbook with no sheets when a sheet operation is performed git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1496516 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
4f6728ccd4
commit
7067e87b8b
|
@ -429,8 +429,12 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
|
|||
private void validateSheetIndex(int index) {
|
||||
int lastSheetIx = _sheets.size() - 1;
|
||||
if (index < 0 || index > lastSheetIx) {
|
||||
String range = "(0.." + lastSheetIx + ")";
|
||||
if (lastSheetIx == -1) {
|
||||
range = "(no sheets)";
|
||||
}
|
||||
throw new IllegalArgumentException("Sheet index ("
|
||||
+ index +") is out of range (0.." + lastSheetIx + ")");
|
||||
+ index +") is out of range " + range);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1040,8 +1040,12 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook, Iterable<X
|
|||
private void validateSheetIndex(int index) {
|
||||
int lastSheetIx = sheets.size() - 1;
|
||||
if (index < 0 || index > lastSheetIx) {
|
||||
String range = "(0.." + lastSheetIx + ")";
|
||||
if (lastSheetIx == -1) {
|
||||
range = "(no sheets)";
|
||||
}
|
||||
throw new IllegalArgumentException("Sheet index ("
|
||||
+ index +") is out of range (0.." + lastSheetIx + ")");
|
||||
+ index +") is out of range " + range);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -45,6 +45,8 @@ public abstract class BaseTestWorkbook extends TestCase {
|
|||
fail("should have thrown exceptiuon due to invalid sheet index");
|
||||
} catch (IllegalArgumentException e) {
|
||||
// expected during successful test
|
||||
// no negative index in the range message
|
||||
assertFalse(e.getMessage().contains("-1"));
|
||||
}
|
||||
|
||||
Sheet sheet0 = wb.createSheet();
|
||||
|
|
Loading…
Reference in New Issue