]> source.dussan.org Git - poi.git/commitdiff
avoid NPE when setting line properties if linewidth is zero
authorYegor Kozlov <yegor@apache.org>
Mon, 2 Jul 2012 08:07:16 +0000 (08:07 +0000)
committerYegor Kozlov <yegor@apache.org>
Mon, 2 Jul 2012 08:07:16 +0000 (08:07 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1356102 13f79535-47bb-0310-9956-ffa450edef68

src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSimpleShape.java
src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFSimpleShape.java

index 6e4768399bc8d2c60a6c5c12a5da457b39362bb3..d6cfa7fba3c6efd0c5c489f7e9e88778c4f18606 100644 (file)
@@ -299,7 +299,7 @@ public abstract class XSLFSimpleShape extends XSLFShape {
     public void setLineWidth(double width) {\r
         CTShapeProperties spPr = getSpPr();\r
         if (width == 0.) {\r
-            if (spPr.isSetLn())\r
+            if (spPr.isSetLn() && spPr.getLn().isSetW())\r
                 spPr.getLn().unsetW();\r
         } else {\r
             CTLineProperties ln = spPr.isSetLn() ? spPr.getLn() : spPr\r
@@ -353,7 +353,7 @@ public abstract class XSLFSimpleShape extends XSLFShape {
     public void setLineDash(LineDash dash) {\r
         CTShapeProperties spPr = getSpPr();\r
         if (dash == null) {\r
-            if (spPr.isSetLn())\r
+            if (spPr.isSetLn() &&  spPr.getLn().isSetPrstDash())\r
                 spPr.getLn().unsetPrstDash();\r
         } else {\r
             CTPresetLineDashProperties val = CTPresetLineDashProperties.Factory\r
@@ -406,7 +406,7 @@ public abstract class XSLFSimpleShape extends XSLFShape {
     public void setLineCap(LineCap cap) {\r
         CTShapeProperties spPr = getSpPr();\r
         if (cap == null) {\r
-            if (spPr.isSetLn())\r
+            if (spPr.isSetLn() && spPr.getLn().isSetCap())\r
                 spPr.getLn().unsetCap();\r
         } else {\r
             CTLineProperties ln = spPr.isSetLn() ? spPr.getLn() : spPr\r
index dc00fff69f7b07ae8db9a6efb81028b680697c0d..f0d57241dbf3446d564924480179b70ada9f3bcf 100644 (file)
@@ -100,6 +100,20 @@ public class TestXSLFSimpleShape extends TestCase {
         assertEquals(null, shape.getLineColor());\r
         // setting dash width to null unsets the SolidFill element\r
         assertFalse(shape.getSpPr().getLn().isSetSolidFill());\r
+\r
+        XSLFSimpleShape ln2 = slide.createAutoShape();\r
+        ln2.setLineDash(LineDash.DOT);\r
+        assertEquals(LineDash.DOT, ln2.getLineDash());\r
+        ln2.setLineWidth(0.);\r
+        assertEquals(0., ln2.getLineWidth());\r
+\r
+        XSLFSimpleShape ln3 = slide.createAutoShape();\r
+        ln3.setLineWidth(1.);\r
+        assertEquals(1., ln3.getLineWidth());\r
+        ln3.setLineDash(null);\r
+        assertEquals(null, ln3.getLineDash());\r
+        ln3.setLineCap(null);\r
+        assertEquals(null, ln3.getLineDash());\r
     }\r
 \r
     public void testFill() {\r