From 51653729ce39bab500b910cfc4ee07e21fe2beaf Mon Sep 17 00:00:00 2001 From: Nick Burch Date: Fri, 18 Feb 2011 15:29:22 +0000 Subject: [PATCH] Fix bug #50795 - Avoid NPE from xmlbeans when moving XSSF Comments from one cell to another git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1072022 13f79535-47bb-0310-9956-ffa450edef68 --- src/documentation/content/xdocs/status.xml | 1 + .../poi/xssf/usermodel/XSSFComment.java | 11 +++- .../poi/xssf/usermodel/TestXSSFBugs.java | 52 ++++++++++++++++++ test-data/spreadsheet/50795.xlsx | Bin 0 -> 11594 bytes 4 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 test-data/spreadsheet/50795.xlsx diff --git a/src/documentation/content/xdocs/status.xml b/src/documentation/content/xdocs/status.xml index ef158f1f93..44524a32ae 100644 --- a/src/documentation/content/xdocs/status.xml +++ b/src/documentation/content/xdocs/status.xml @@ -34,6 +34,7 @@ + 50795 - Avoid NPE from xmlbeans when moving XSSF Comments from one cell to another 46664 - When creating HSSF Print Areas, ensure the named range is reference based not value based 50756 - When formatting numbers based on their Cell Style, treat GENERAL the same as the more typical General fixed HSSFWorkbook.createCellStyle to throw exception if the maximum number of cell styles was exceeded diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFComment.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFComment.java index 9d6c34cd47..f75b250624 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFComment.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFComment.java @@ -116,7 +116,16 @@ public class XSSFComment implements Comment { _comment.setRef(ref.formatAsString()); _comments.referenceUpdated(oldRef, _comment); - if(_vmlShape != null) _vmlShape.getClientDataArray(0).setColumnArray(0, new BigInteger(String.valueOf(col))); + if(_vmlShape != null) { + _vmlShape.getClientDataArray(0).setColumnArray( + new BigInteger[] { new BigInteger(String.valueOf(col)) } + ); + + // There is a very odd xmlbeans bug when changing the column + // arrays which can lead to corrupt pointer + // This call seems to fix them again... See bug #50795 + _vmlShape.getClientDataList().toString(); + } } /** diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java index b45a5df6c8..abc9fc73bc 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java @@ -620,4 +620,56 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues { assertEquals("SUM(\n1,2\n)", c.getCellFormula()); assertEquals(3.0, c.getNumericCellValue()); } + + /** + * Moving a cell comment from one cell to another + */ + public void test50795() throws Exception { + XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("50795.xlsx"); + XSSFSheet sheet = wb.getSheetAt(0); + XSSFRow row = sheet.getRow(0); + + XSSFCell cellWith = row.getCell(0); + XSSFCell cellWithoutComment = row.getCell(1); + + assertNotNull(cellWith.getCellComment()); + assertNull(cellWithoutComment.getCellComment()); + + String exp = "\u0410\u0432\u0442\u043e\u0440:\ncomment"; + XSSFComment comment = cellWith.getCellComment(); + assertEquals(exp, comment.getString().getString()); + + + // Check we can write it out and read it back as-is + wb = XSSFTestDataSamples.writeOutAndReadBack(wb); + sheet = wb.getSheetAt(0); + row = sheet.getRow(0); + cellWith = row.getCell(0); + cellWithoutComment = row.getCell(1); + + // Double check things are as expected + assertNotNull(cellWith.getCellComment()); + assertNull(cellWithoutComment.getCellComment()); + comment = cellWith.getCellComment(); + assertEquals(exp, comment.getString().getString()); + + + // Move the comment + cellWithoutComment.setCellComment(comment); + + + // Write out and re-check + wb = XSSFTestDataSamples.writeOutAndReadBack(wb); + sheet = wb.getSheetAt(0); + row = sheet.getRow(0); + + // Ensure it swapped over + cellWith = row.getCell(0); + cellWithoutComment = row.getCell(1); + assertNull(cellWith.getCellComment()); + assertNotNull(cellWithoutComment.getCellComment()); + + comment = cellWithoutComment.getCellComment(); + assertEquals(exp, comment.getString().getString()); + } } diff --git a/test-data/spreadsheet/50795.xlsx b/test-data/spreadsheet/50795.xlsx new file mode 100644 index 0000000000000000000000000000000000000000..a58aeec7cc564bdf18b9bfe0a4325826955e81b4 GIT binary patch literal 11594 zcmeHtWmH_*wr=4T90I{TxI2X4?oJ@MySux)TX1(xkPw0v1W5?4A-G#`c?I3)q?^t; z@4PYIy+7{lJqER_1~tE$d#-OyTT@;N0uloN4S)pz0K|ZGsgA8&FaY2L8UR2C%z$YM z*;qRoSv%?|yV)8!yry@xvLwoz0He$SfP=pO_w_%@0-scdWIytwyw5mC8q!95{h=FM z=o^u{GWsFd#Jr!isS5{B*WxS>onZG@93>=eQ&XPBksXe)&xV>$fjA_u_L-T)uSmd( z+iR`k!kVWI_EpKm2cD_8!lX@sg#*uz^jT-2J_MHI8QCK#snjM+eBU8XeH>kAJB9q-6poPd?+j2^AbD{xtf9#qt_JbzyrduY#d# z7)LhWuG?l?ARv0%Colg>`Swdpu$hL-9E8@(DD$rJVk1;j9n}nk5vv2=t3fw|Dw0&S zWtn%JSKOE3^F`k|J!ZttJ(iGo%F3)$IW>IhdkH}_ySsw`$p2}tHmWd^{s8?)8nhJ= z0K;H9_C}Tt4D|P}M0o>$@6rD;dowbAM7E3ZN$mx5U7xvc7lnL?l8DzU!CbMppX6R2|mDEK<;It%Olj^hL%V8iK?${T`F)9q`nSM@qR$?@lxcVZv zgFv2+cf8Xa7RCdnjPH{7qOO@$#>SOl%}YN;Hj+OZooCQ_Rmd2jbY!+9U2sq$0P{F= z3>A1qVgQj%F{34Sa@WLZM28+9;8`JyM`r^9(?tusqt$o_zY;=4FCV3qO!P7b}45+UwPvL_{e|p&nti%t9j=9oevsvblS2hh?-vw& z(XFPkBe2T+N`I1W@C;|u$!!90fLErO`Fh+}zlbV2$=|kuok%tyX86vcwZ&S>({9xy zCb?R@-v(>g5QQszYm|s4^%YqkkRq&`sJd%~BN&*XTZh|aD8)F-rq{pWJI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