From c3adfbaf480348ae3f6462562e8e334c70724940 Mon Sep 17 00:00:00 2001 From: Yegor Kozlov Date: Mon, 2 Jul 2012 08:07:16 +0000 Subject: [PATCH] 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 --- .../apache/poi/xslf/usermodel/XSLFSimpleShape.java | 6 +++--- .../poi/xslf/usermodel/TestXSLFSimpleShape.java | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSimpleShape.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSimpleShape.java index 6e4768399b..d6cfa7fba3 100644 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSimpleShape.java +++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSimpleShape.java @@ -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 diff --git a/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFSimpleShape.java b/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFSimpleShape.java index dc00fff69f..f0d57241db 100644 --- a/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFSimpleShape.java +++ b/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFSimpleShape.java @@ -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() { -- 2.39.5