mirror of
https://github.com/apache/poi.git
synced 2026-02-27 20:40:08 +08:00
Fix NPE in XWPFParagraph.getCTSpacing(). (#950)
We recently changed the getters so they don't create the PPr object if it doesn't exist, but we missed adding one null check for the new situation. Add a test to exercise all the getters in a case where there isn't a PPr object.
This commit is contained in:
parent
b4326363d6
commit
775da74dee
@ -1457,6 +1457,9 @@ public class XWPFParagraph implements IBodyElement, IRunBody, ISDTContents, Para
|
|||||||
*/
|
*/
|
||||||
private CTSpacing getCTSpacing(boolean create) {
|
private CTSpacing getCTSpacing(boolean create) {
|
||||||
CTPPr pr = getCTPPr(create);
|
CTPPr pr = getCTPPr(create);
|
||||||
|
if (pr == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
CTSpacing ct = pr.getSpacing();
|
CTSpacing ct = pr.getSpacing();
|
||||||
if (create && ct == null) {
|
if (create && ct == null) {
|
||||||
ct = pr.addNewSpacing();
|
ct = pr.addNewSpacing();
|
||||||
|
|||||||
@ -921,6 +921,50 @@ public final class TestXWPFParagraph {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testGettersWithEmptyParagraphProperties() throws IOException {
|
||||||
|
try (XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("emptyPPr.docx")) {
|
||||||
|
XWPFParagraph p = doc.getParagraphArray(0);
|
||||||
|
|
||||||
|
assertNull(p.getNumID());
|
||||||
|
assertNull(p.getNumIlvl());
|
||||||
|
assertNull(p.getNumFmt());
|
||||||
|
assertNull(p.getNumLevelText());
|
||||||
|
assertNull(p.getNumStartOverride());
|
||||||
|
assertFalse(p.isKeepNext());
|
||||||
|
|
||||||
|
assertFalse(p.isAlignmentSet());
|
||||||
|
assertEquals(ParagraphAlignment.LEFT, p.getAlignment());
|
||||||
|
assertEquals(TextAlignment.AUTO, p.getVerticalAlignment());
|
||||||
|
|
||||||
|
assertEquals(Borders.NONE, p.getBorderTop());
|
||||||
|
assertEquals(Borders.NONE, p.getBorderBottom());
|
||||||
|
assertEquals(Borders.NONE, p.getBorderLeft());
|
||||||
|
assertEquals(Borders.NONE, p.getBorderRight());
|
||||||
|
assertEquals(Borders.NONE, p.getBorderBetween());
|
||||||
|
|
||||||
|
assertEquals(-1, p.getSpacingAfter());
|
||||||
|
assertEquals(-1, p.getSpacingAfterLines());
|
||||||
|
assertEquals(-1, p.getSpacingBefore());
|
||||||
|
assertEquals(-1, p.getSpacingBeforeLines());
|
||||||
|
assertEquals(-1, p.getSpacingBetween());
|
||||||
|
assertEquals(LineSpacingRule.AUTO, p.getSpacingLineRule());
|
||||||
|
|
||||||
|
assertEquals(-1, p.getIndentationLeft());
|
||||||
|
assertEquals(-1, p.getIndentationLeftChars());
|
||||||
|
assertEquals(-1, p.getIndentationRight());
|
||||||
|
assertEquals(-1, p.getIndentationRightChars());
|
||||||
|
assertEquals(-1, p.getIndentationHanging());
|
||||||
|
assertEquals(-1, p.getIndentationFirstLine());
|
||||||
|
|
||||||
|
assertFalse(p.isPageBreak());
|
||||||
|
assertFalse(p.isWordWrapped());
|
||||||
|
|
||||||
|
assertNull(p.getStyleID());
|
||||||
|
assertNull(p.getStyle());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static void checkSearchText(XWPFParagraph paragraph, String search, int beginRun, int endRun, int beginText, int endText,
|
private static void checkSearchText(XWPFParagraph paragraph, String search, int beginRun, int endRun, int beginText, int endText,
|
||||||
int beginChar, int endChar) {
|
int beginChar, int endChar) {
|
||||||
TextSegment result = paragraph.searchText(search, new PositionInParagraph());
|
TextSegment result = paragraph.searchText(search, new PositionInParagraph());
|
||||||
|
|||||||
BIN
test-data/document/emptyPPr.docx
Normal file
BIN
test-data/document/emptyPPr.docx
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user