Bug 58315: Avoid NPE for RichTextString without font-details

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1701382 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Dominik Stadler 2015-09-05 12:57:04 +00:00
parent 7da84c99f2
commit 062cf73c07
3 changed files with 26 additions and 0 deletions

View File

@ -435,6 +435,11 @@ public class XSSFRichTextString implements RichTextString {
protected static CTFont toCTFont(CTRPrElt pr){ protected static CTFont toCTFont(CTRPrElt pr){
CTFont ctFont = CTFont.Factory.newInstance(); 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.sizeOfBArray() > 0) ctFont.addNewB().setVal(pr.getBArray(0).getVal());
if(pr.sizeOfUArray() > 0) ctFont.addNewU().setVal(pr.getUArray(0).getVal()); if(pr.sizeOfUArray() > 0) ctFont.addNewU().setVal(pr.getUArray(0).getVal());
if(pr.sizeOfIArray() > 0) ctFont.addNewI().setVal(pr.getIArray(0).getVal()); if(pr.sizeOfIArray() > 0) ctFont.addNewI().setVal(pr.getIArray(0).getVal());

View File

@ -2636,4 +2636,25 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
wb.close(); 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();
}
} }

Binary file not shown.