avoid NPE when setting line properties if linewidth is zero

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1356102 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Yegor Kozlov 2012-07-02 08:07:16 +00:00
parent 2a63a73b98
commit 2257c01910
2 changed files with 17 additions and 3 deletions

View File

@ -299,7 +299,7 @@ public abstract class XSLFSimpleShape extends XSLFShape {
public void setLineWidth(double width) {
CTShapeProperties spPr = getSpPr();
if (width == 0.) {
if (spPr.isSetLn())
if (spPr.isSetLn() && spPr.getLn().isSetW())
spPr.getLn().unsetW();
} else {
CTLineProperties ln = spPr.isSetLn() ? spPr.getLn() : spPr
@ -353,7 +353,7 @@ public abstract class XSLFSimpleShape extends XSLFShape {
public void setLineDash(LineDash dash) {
CTShapeProperties spPr = getSpPr();
if (dash == null) {
if (spPr.isSetLn())
if (spPr.isSetLn() && spPr.getLn().isSetPrstDash())
spPr.getLn().unsetPrstDash();
} else {
CTPresetLineDashProperties val = CTPresetLineDashProperties.Factory
@ -406,7 +406,7 @@ public abstract class XSLFSimpleShape extends XSLFShape {
public void setLineCap(LineCap cap) {
CTShapeProperties spPr = getSpPr();
if (cap == null) {
if (spPr.isSetLn())
if (spPr.isSetLn() && spPr.getLn().isSetCap())
spPr.getLn().unsetCap();
} else {
CTLineProperties ln = spPr.isSetLn() ? spPr.getLn() : spPr

View File

@ -100,6 +100,20 @@ public class TestXSLFSimpleShape extends TestCase {
assertEquals(null, shape.getLineColor());
// setting dash width to null unsets the SolidFill element
assertFalse(shape.getSpPr().getLn().isSetSolidFill());
XSLFSimpleShape ln2 = slide.createAutoShape();
ln2.setLineDash(LineDash.DOT);
assertEquals(LineDash.DOT, ln2.getLineDash());
ln2.setLineWidth(0.);
assertEquals(0., ln2.getLineWidth());
XSLFSimpleShape ln3 = slide.createAutoShape();
ln3.setLineWidth(1.);
assertEquals(1., ln3.getLineWidth());
ln3.setLineDash(null);
assertEquals(null, ln3.getLineDash());
ln3.setLineCap(null);
assertEquals(null, ln3.getLineDash());
}
public void testFill() {