poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cen...@apache.org
Subject svn commit: r1701382 - in /poi/trunk: src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRichTextString.java src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java test-data/spreadsheet/58315.xlsx
Date Sat, 05 Sep 2015 12:57:05 GMT
Author: centic
Date: Sat Sep  5 12:57:04 2015
New Revision: 1701382

URL: http://svn.apache.org/r1701382
Log:
Bug 58315: Avoid NPE for RichTextString without font-details

Added:
    poi/trunk/test-data/spreadsheet/58315.xlsx
Modified:
    poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRichTextString.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRichTextString.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRichTextString.java?rev=1701382&r1=1701381&r2=1701382&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRichTextString.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRichTextString.java Sat Sep
 5 12:57:04 2015
@@ -435,6 +435,11 @@ public class XSSFRichTextString implemen
     protected static CTFont toCTFont(CTRPrElt pr){
         CTFont ctFont =  CTFont.Factory.newInstance();
 
+        // Bug 58315: there are files where there is no pr-entry for a RichTextString
+        if(pr == null) {
+            return ctFont;
+        }
+
         if(pr.sizeOfBArray() > 0) ctFont.addNewB().setVal(pr.getBArray(0).getVal());
         if(pr.sizeOfUArray() > 0) ctFont.addNewU().setVal(pr.getUArray(0).getVal());
         if(pr.sizeOfIArray() > 0) ctFont.addNewI().setVal(pr.getIArray(0).getVal());

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=1701382&r1=1701381&r2=1701382&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 Sat Sep
 5 12:57:04 2015
@@ -2636,4 +2636,25 @@ public final class TestXSSFBugs extends
     
         wb.close();
     }
+
+
+    @Test
+    public void test58315() throws IOException {
+        Workbook wb = XSSFTestDataSamples.openSampleWorkbook("58315.xlsx");
+        Cell cell = wb.getSheetAt(0).getRow(0).getCell(0);
+        assertNotNull(cell);
+        StringBuilder tmpCellContent = new StringBuilder(cell.getStringCellValue());
+        XSSFRichTextString richText = (XSSFRichTextString) cell.getRichStringCellValue();
+
+        for (int i = richText.length() - 1; i >= 0; i--) {
+            Font f = richText.getFontAtIndex(i);
+            if (f != null && f.getStrikeout()) {
+                tmpCellContent.deleteCharAt(i);
+            }
+        }
+        String result = tmpCellContent.toString();
+        assertEquals("320 350", result);
+
+        wb.close();
+    }
 }

Added: poi/trunk/test-data/spreadsheet/58315.xlsx
URL: http://svn.apache.org/viewvc/poi/trunk/test-data/spreadsheet/58315.xlsx?rev=1701382&view=auto
==============================================================================
Binary files poi/trunk/test-data/spreadsheet/58315.xlsx (added) and poi/trunk/test-data/spreadsheet/58315.xlsx
Sat Sep  5 12:57:04 2015 differ



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


Mime
View raw message