aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/java/org/apache/poi/hssf/model/InternalWorkbook.java18
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java8
-rw-r--r--test-data/spreadsheet/55982.xlsbin0 -> 133120 bytes
3 files changed, 19 insertions, 7 deletions
diff --git a/src/java/org/apache/poi/hssf/model/InternalWorkbook.java b/src/java/org/apache/poi/hssf/model/InternalWorkbook.java
index 0b11818fdf..7ca7c942df 100644
--- a/src/java/org/apache/poi/hssf/model/InternalWorkbook.java
+++ b/src/java/org/apache/poi/hssf/model/InternalWorkbook.java
@@ -801,20 +801,24 @@ public final class InternalWorkbook {
/**
* make the tabid record look like the current situation.
- *
- * @return number of bytes written in the TabIdRecord
*/
- private int fixTabIdRecord() {
- TabIdRecord tir = ( TabIdRecord ) records.get(records.getTabpos());
- int sz = tir.getRecordSize();
+ private void fixTabIdRecord() {
+ Record rec = records.get(records.getTabpos());
+
+ // see bug 55982, quite a number of documents do not have a TabIdRecord and
+ // thus there is no way to do the fixup here,
+ // we use the same check on Tabpos as done in other places
+ if(records.getTabpos() <= 0) {
+ return;
+ }
+
+ TabIdRecord tir = ( TabIdRecord ) rec;
short[] tia = new short[ boundsheets.size() ];
for (short k = 0; k < tia.length; k++) {
tia[ k ] = k;
}
tir.setTabIdArray(tia);
- return tir.getRecordSize() - sz;
-
}
/**
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java b/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java
index 7cc9b4ea59..17861e289a 100644
--- a/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java
@@ -3001,4 +3001,12 @@ public final class TestBugs extends BaseTestBugzillaIssues {
wb.close();
}
+
+ @Test
+ public void test55982() throws IOException {
+ Workbook wb = HSSFTestDataSamples.openSampleWorkbook("55982.xls");
+ Sheet newSheet = wb.cloneSheet(1);
+ assertNotNull(newSheet);
+ wb.close();
+ }
}
diff --git a/test-data/spreadsheet/55982.xls b/test-data/spreadsheet/55982.xls
new file mode 100644
index 0000000000..2e09ddb531
--- /dev/null
+++ b/test-data/spreadsheet/55982.xls
Binary files differ