You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ni...@apache.org on 2011/02/18 16:29:23 UTC

svn commit: r1072022 - in /poi/trunk: 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

Author: nick
Date: Fri Feb 18 15:29:22 2011
New Revision: 1072022

URL: http://svn.apache.org/viewvc?rev=1072022&view=rev
Log:
Fix bug #50795 - Avoid NPE from xmlbeans when moving XSSF Comments from one cell to another

Added:
    poi/trunk/test-data/spreadsheet/50795.xlsx   (with props)
Modified:
    poi/trunk/src/documentation/content/xdocs/status.xml
    poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFComment.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java

Modified: poi/trunk/src/documentation/content/xdocs/status.xml
URL: http://svn.apache.org/viewvc/poi/trunk/src/documentation/content/xdocs/status.xml?rev=1072022&r1=1072021&r2=1072022&view=diff
==============================================================================
--- poi/trunk/src/documentation/content/xdocs/status.xml (original)
+++ poi/trunk/src/documentation/content/xdocs/status.xml Fri Feb 18 15:29:22 2011
@@ -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>

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFComment.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFComment.java?rev=1072022&r1=1072021&r2=1072022&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFComment.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFComment.java Fri Feb 18 15:29:22 2011
@@ -116,7 +116,16 @@ public class XSSFComment implements Comm
         _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();
+        }
 	}
 
     /**

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java?rev=1072022&r1=1072021&r2=1072022&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java Fri Feb 18 15:29:22 2011
@@ -620,4 +620,56 @@ public final class TestXSSFBugs extends 
        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());
+    }
 }

Added: poi/trunk/test-data/spreadsheet/50795.xlsx
URL: http://svn.apache.org/viewvc/poi/trunk/test-data/spreadsheet/50795.xlsx?rev=1072022&view=auto
==============================================================================
Binary file - no diff available.

Propchange: poi/trunk/test-data/spreadsheet/50795.xlsx
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org