]> source.dussan.org Git - poi.git/commitdiff
Bug 58315: Avoid NPE for RichTextString without font-details
authorDominik Stadler <centic@apache.org>
Sat, 5 Sep 2015 12:57:04 +0000 (12:57 +0000)
committerDominik Stadler <centic@apache.org>
Sat, 5 Sep 2015 12:57:04 +0000 (12:57 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1701382 13f79535-47bb-0310-9956-ffa450edef68

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 [new file with mode: 0644]

index a7f9b3a8e35a9da2884e3c98082d1bb4485d2026..63f7a3ba8fd2c6fcda409e54e7b081aaecacd76e 100644 (file)
@@ -435,6 +435,11 @@ public class XSSFRichTextString implements RichTextString {
     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());
index 566d1d712a7d1badcfa26be88dbd60b2a259c699..f487726c95a2b661d32a256a347dda99a57d4fa2 100644 (file)
@@ -2636,4 +2636,25 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
     
         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();
+    }
 }
diff --git a/test-data/spreadsheet/58315.xlsx b/test-data/spreadsheet/58315.xlsx
new file mode 100644 (file)
index 0000000..0da751e
Binary files /dev/null and b/test-data/spreadsheet/58315.xlsx differ