]> source.dussan.org Git - poi.git/commitdiff
Fix bug #50795 - Avoid NPE from xmlbeans when moving XSSF Comments from one cell...
authorNick Burch <nick@apache.org>
Fri, 18 Feb 2011 15:29:22 +0000 (15:29 +0000)
committerNick Burch <nick@apache.org>
Fri, 18 Feb 2011 15:29:22 +0000 (15:29 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1072022 13f79535-47bb-0310-9956-ffa450edef68

src/documentation/content/xdocs/status.xml
src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFComment.java
src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java
test-data/spreadsheet/50795.xlsx [new file with mode: 0644]

index ef158f1f93f93184fc0d4e588201250d40c532b3..44524a32ae4203707dc9288689df7ad0365e05ef 100644 (file)
@@ -34,6 +34,7 @@
 
     <changes>
         <release version="3.8-beta1" date="2010-??-??">
+           <action dev="poi-developers" type="fix">50795 - Avoid NPE from xmlbeans when moving XSSF Comments from one cell to another</action>
            <action dev="poi-developers" type="fix">46664 - When creating HSSF Print Areas, ensure the named range is reference based not value based</action>
            <action dev="poi-developers" type="fix">50756 - When formatting numbers based on their Cell Style, treat GENERAL the same as the more typical General</action>
            <action dev="poi-developers" type="fix">fixed HSSFWorkbook.createCellStyle to throw exception if the maximum number of cell styles was exceeded</action>
index 9d6c34cd47e037888e3485a0fd62c32a65e256e7..f75b250624e58009a7ba3b203f5db322b4da658e 100644 (file)
@@ -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();
+        }
        }
 
     /**
index b45a5df6c8b2cd071f451b263518499e820da6aa..abc9fc73bc5ca44c5ac299feda458ed3204213a8 100644 (file)
@@ -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 (file)
index 0000000..a58aeec
Binary files /dev/null and b/test-data/spreadsheet/50795.xlsx differ