mirror of
https://github.com/apache/poi.git
synced 2026-02-27 20:40:08 +08:00
[bug-64600] Avoid XWPF NPE when styleid is null. Thanks to Sayi. This closes #186
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1879859 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
2f2d6c606a
commit
709a3eb32c
@ -154,11 +154,7 @@ public class XWPFStyles extends POIXMLDocumentPart {
|
||||
* @return true if style exist, false if style not exist
|
||||
*/
|
||||
public boolean styleExist(String styleID) {
|
||||
for (XWPFStyle style : listStyle) {
|
||||
if (style.getStyleId().equals(styleID))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return null != getStyle(styleID);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -182,12 +178,8 @@ public class XWPFStyles extends POIXMLDocumentPart {
|
||||
*/
|
||||
public XWPFStyle getStyle(String styleID) {
|
||||
for (XWPFStyle style : listStyle) {
|
||||
try {
|
||||
if (style.getStyleId().equals(styleID))
|
||||
return style;
|
||||
} catch (NullPointerException e) {
|
||||
// Ignore NPE
|
||||
}
|
||||
if (null != style.getStyleId() && style.getStyleId().equals(styleID))
|
||||
return style;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -217,6 +217,11 @@ public final class TestXWPFStyles {
|
||||
assertNotNull(styles.getStyle("NoList"));
|
||||
assertNull(styles.getStyle("EmptyCellLayoutStyle"));
|
||||
assertNotNull(styles.getStyle("BalloonText"));
|
||||
|
||||
// Bug 64600: styleExist throws NPE
|
||||
assertTrue(styles.styleExist("NoList"));
|
||||
assertFalse(styles.styleExist("EmptyCellLayoutStyle"));
|
||||
assertTrue(styles.styleExist("BalloonText"));
|
||||
} catch (NullPointerException e) {
|
||||
fail(e.toString());
|
||||
}
|
||||
@ -235,4 +240,5 @@ public final class TestXWPFStyles {
|
||||
assertEquals(styleName, style.getName());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user