From 2c7987545b7f9bc6cab84a9c812c512092ad7fc9 Mon Sep 17 00:00:00 2001 From: Dominik Stadler Date: Mon, 13 Apr 2015 12:19:11 +0000 Subject: [PATCH] Bug 57163: Fix possible NullPointerException when a spreadsheet has no LinkTable and we try to adjust it during sheet removal. git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1673168 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/poi/hssf/model/InternalWorkbook.java | 11 ++++++----- .../org/apache/poi/hssf/usermodel/TestBugs.java | 10 ++++++++++ test-data/spreadsheet/57163.xls | Bin 0 -> 6656 bytes 3 files changed, 16 insertions(+), 5 deletions(-) create mode 100644 test-data/spreadsheet/57163.xls diff --git a/src/java/org/apache/poi/hssf/model/InternalWorkbook.java b/src/java/org/apache/poi/hssf/model/InternalWorkbook.java index 3c3b91b148..a2670978ea 100644 --- a/src/java/org/apache/poi/hssf/model/InternalWorkbook.java +++ b/src/java/org/apache/poi/hssf/model/InternalWorkbook.java @@ -774,11 +774,12 @@ public final class InternalWorkbook { } } - // also tell the LinkTable about the removed sheet - // +1 because we already removed it from the count of sheets! - for(int i = sheetIndex+1;i < getNumSheets()+1;i++) { - // also update the link-table as otherwise references might point at invalid sheets - linkTable.removeSheet(i); + if (linkTable != null) { + // also tell the LinkTable about the removed sheet + // +1 because we already removed it from the count of sheets! + for(int i = sheetIndex+1;i < getNumSheets()+1;i++) { + linkTable.removeSheet(i); + } } } diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java b/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java index 73256b6897..0bb1de24b4 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java @@ -2716,4 +2716,14 @@ public final class TestBugs extends BaseTestBugzillaIssues { Workbook wb = openSample("57456.xls"); wb.close(); } + + @Test + public void test57163() throws IOException { + Workbook wb = openSample("57163.xls"); + + while (wb.getNumberOfSheets() > 1) { + wb.removeSheetAt(1); + } + wb.close(); + } } diff --git a/test-data/spreadsheet/57163.xls b/test-data/spreadsheet/57163.xls new file mode 100644 index 0000000000000000000000000000000000000000..402c954e19b8070b5ae6448700895ab94816868a GIT binary patch literal 6656 zcmeHLTWDNW6y0a$PI9M7Gm}YLYir|8w0WoIp*BTgCTY`J?28)FkD?~yq^6xTp@~?* z$0RifVnM0kPf-f_@qx7n`k`Rrmte&z6sjPk`c?E}DvDHW#NZ4YO-nR z_7~aIzgC@P{c|gDt+isgd;RIZ>Bqf5rt?pq&+}ghtOSaH0Dvn%ih&SN0+a%)fYrcF zz#8CYU@fo?xCK}blmWK_7ElgU0Jj0R0~>%!pbDr4YJggx4yXqjfQ`T%0O!%<=P1^gyAlolPw2du2v556=QKue5 zkD_f(!bsax9%2m-?DQnkA~~%~KGA8Lwm?)2i`9yZQON{8*!H+iD|A|fRLMuW&39VT z1l#-^wUW=jq7TAZ@u?2@z<%kGn531;(v_AOg%}|ge0$gKu6-Rlr}f#Hkl&IPMw6mR zi*gQ3%YV&I&RH*1Ka-rjE>!>jE1$rcTAZFksdcWi*CCNEugM^<&mgbOAou@Ge!_!u z6_+IQVBD+o;&`6ULvcgrCGmWnm&Sd`$6&ik#^H%yL_>P)?&$EyIL^bUb9(u0HB)k$ zp&QP#mbAQ#y7~A`DH9OsKCa{^IY>XA=w(I8OVHoa$+K(T2L!E;p!G0M$y%f!LBIbg zqC`_h6_lBiDvUHNWtVv~;HEIqnTeag{2iA?#9Sp2hLjHRrXYEEz1VIjIL{3gLh0ie zAg5fc2M~m+Ki|6i&92_P?T>1CTnDMTAKAdgl%$NJWXh=3E$VbSrt6j>#3>h5DO+&E zR7f{Y`G7=aSS;C%{3+y&h6Zr<596*WGn$P1jqOGo(#=K%+B8Ws(hl5l58+PwhaHt0 zokrMbME9-6Hslt%-YduScwf+ICFa(m=~8=@i?0TMtl`2~!-Yh9jf+2pN%^s2O8>^B zUe&8q`&6#vLG)c9&+5xu)N2L2$Uz=n>UP*~Z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