You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ce...@apache.org on 2019/03/02 12:28:20 UTC

svn commit: r1854639 - in /poi/trunk: src/integrationtest/org/apache/poi/stress/ src/java/org/apache/poi/sl/draw/ src/ooxml/java/org/apache/poi/xddf/usermodel/ src/ooxml/java/org/apache/poi/xslf/usermodel/ src/ooxml/testcases/org/apache/poi/xslf/ test-...

Author: centic
Date: Sat Mar  2 12:28:19 2019
New Revision: 1854639

URL: http://svn.apache.org/viewvc?rev=1854639&view=rev
Log:
Bug 63200: Avoid NullPointerException in XSLFShape.selectPaint() and check some more in integration tests

Added:
    poi/trunk/test-data/slideshow/63200.pptx
Modified:
    poi/trunk/src/integrationtest/org/apache/poi/stress/SlideShowHandler.java
    poi/trunk/src/java/org/apache/poi/sl/draw/DrawPaint.java
    poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/XDDFGradientFillProperties.java
    poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFShape.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/TestXSLFBugs.java

Modified: poi/trunk/src/integrationtest/org/apache/poi/stress/SlideShowHandler.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/integrationtest/org/apache/poi/stress/SlideShowHandler.java?rev=1854639&r1=1854638&r2=1854639&view=diff
==============================================================================
--- poi/trunk/src/integrationtest/org/apache/poi/stress/SlideShowHandler.java (original)
+++ poi/trunk/src/integrationtest/org/apache/poi/stress/SlideShowHandler.java Sat Mar  2 12:28:19 2019
@@ -16,8 +16,18 @@
 ==================================================================== */
 package org.apache.poi.stress;
 
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
+import org.apache.poi.sl.draw.Drawable;
+import org.apache.poi.sl.usermodel.GroupShape;
+import org.apache.poi.sl.usermodel.Notes;
+import org.apache.poi.sl.usermodel.PictureData;
+import org.apache.poi.sl.usermodel.Shape;
+import org.apache.poi.sl.usermodel.SimpleShape;
+import org.apache.poi.sl.usermodel.Slide;
+import org.apache.poi.sl.usermodel.SlideShow;
+import org.apache.poi.sl.usermodel.SlideShowFactory;
+import org.apache.poi.sl.usermodel.TextParagraph;
+import org.apache.poi.sl.usermodel.TextRun;
+import org.apache.poi.sl.usermodel.TextShape;
 
 import java.awt.Dimension;
 import java.awt.Graphics2D;
@@ -28,16 +38,8 @@ import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.lang.ref.WeakReference;
 
-import org.apache.poi.sl.draw.Drawable;
-import org.apache.poi.sl.usermodel.PictureData;
-import org.apache.poi.sl.usermodel.Shape;
-import org.apache.poi.sl.usermodel.ShapeContainer;
-import org.apache.poi.sl.usermodel.Slide;
-import org.apache.poi.sl.usermodel.SlideShow;
-import org.apache.poi.sl.usermodel.SlideShowFactory;
-import org.apache.poi.sl.usermodel.TextParagraph;
-import org.apache.poi.sl.usermodel.TextRun;
-import org.apache.poi.sl.usermodel.TextShape;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
 
 public abstract class SlideShowHandler extends POIFSFileHandler {
     public void handleSlideShow(SlideShow<?,?> ss) throws IOException {
@@ -73,20 +75,50 @@ public abstract class SlideShowHandler e
     private void readContent(SlideShow<?,?> ss) {
         for (Slide<?,?> s : ss.getSlides()) {
             s.getTitle();
-            readText(s);
-            readText(s.getNotes());
-            readText(s.getMasterSheet());
+
+            for (Shape<?,?> shape : s) {
+                readShapes(shape);
+            }
+
+            Notes<?, ?> notes = s.getNotes();
+            if(notes != null) {
+                for (Shape<?, ?> shape : notes) {
+                    readShapes(shape);
+                }
+            }
+
+            for (Shape<?,?> shape : s.getMasterSheet()) {
+                readShapes(shape);
+            }
         }
     }
-    
-    private void readText(ShapeContainer<?,?> sc) {
-        if (sc == null) return;
-        for (Shape<?,?> s : sc) {
-            if (s instanceof TextShape) {
-                for (TextParagraph<?,?,?> tp : (TextShape<?,?>)s) {
-                    for (TextRun tr : tp) {
-                        tr.getRawText();
-                    }
+
+    private void readShapes(Shape<?,?> s) {
+        // recursively walk group-shapes
+        if(s instanceof GroupShape) {
+            GroupShape<? extends Shape, ?> shapes = (GroupShape<? extends Shape, ?>) s;
+            for (Shape<? extends Shape, ?> shape : shapes) {
+                readShapes(shape);
+            }
+        }
+
+        if(s instanceof SimpleShape) {
+            SimpleShape<?, ?> simpleShape = (SimpleShape<?, ?>) s;
+
+            simpleShape.getFillColor();
+            simpleShape.getFillStyle();
+            simpleShape.getStrokeStyle();
+            simpleShape.getLineDecoration();
+        }
+
+        readText(s);
+    }
+
+    private void readText(Shape<?,?> s) {
+        if (s instanceof TextShape) {
+            for (TextParagraph<?,?,?> tp : (TextShape<?,?>)s) {
+                for (TextRun tr : tp) {
+                    tr.getRawText();
                 }
             }
         }

Modified: poi/trunk/src/java/org/apache/poi/sl/draw/DrawPaint.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/sl/draw/DrawPaint.java?rev=1854639&r1=1854638&r2=1854639&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/sl/draw/DrawPaint.java (original)
+++ poi/trunk/src/java/org/apache/poi/sl/draw/DrawPaint.java Sat Mar  2 12:28:19 2019
@@ -407,7 +407,10 @@ public class DrawPaint {
 //        snapToAnchor(p2, anchor);
 
         // gradient paint on the same point throws an exception ... and doesn't make sense
-        return (p1.equals(p2)) ? null : safeFractions((f,c)->new LinearGradientPaint(p1,p2,f,c), fill);
+        // also having less than two fractions will not work
+        return (p1.equals(p2) || fill.getGradientFractions().length < 2) ?
+                null :
+                safeFractions((f,c)->new LinearGradientPaint(p1,p2,f,c), fill);
     }
 
 

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/XDDFGradientFillProperties.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/XDDFGradientFillProperties.java?rev=1854639&r1=1854638&r2=1854639&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/XDDFGradientFillProperties.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/XDDFGradientFillProperties.java Sat Mar  2 12:28:19 2019
@@ -112,7 +112,7 @@ public class XDDFGradientFillProperties
                 .getGsLst()
                 .getGsList()
                 .stream()
-                .map(gs -> new XDDFGradientStop(gs))
+                .map(XDDFGradientStop::new)
                 .collect(Collectors.toList()));
         } else {
             return Collections.emptyList();

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFShape.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFShape.java?rev=1854639&r1=1854638&r2=1854639&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFShape.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFShape.java Sat Mar  2 12:28:19 2019
@@ -431,7 +431,8 @@ public abstract class XSLFShape implemen
     protected static PaintStyle selectPaint(final CTGradientFillProperties gradFill, CTSchemeColor phClr, final XSLFTheme theme) {
 
         @SuppressWarnings("deprecation")
-        final CTGradientStop[] gs = gradFill.getGsLst().getGsArray();
+        final CTGradientStop[] gs = gradFill.getGsLst() == null ?
+                new CTGradientStop[0] : gradFill.getGsLst().getGsArray();
 
         Arrays.sort(gs, (o1, o2) -> {
             int pos1 = o1.getPos();

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/TestXSLFBugs.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/TestXSLFBugs.java?rev=1854639&r1=1854638&r2=1854639&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/TestXSLFBugs.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/TestXSLFBugs.java Sat Mar  2 12:28:19 2019
@@ -966,4 +966,21 @@ public class TestXSLFBugs {
 
         }
     }
+
+    @Test
+    public void bug63200() throws Exception {
+        try (XMLSlideShow ss1 = XSLFTestDataSamples.openSampleDocument("63200.pptx")) {
+            assertEquals(1, ss1.getSlides().size());
+
+            XSLFSlide slide = ss1.getSlides().get(0);
+
+            assertEquals(slide.getShapes().size(), 1);
+            XSLFGroupShape group = (XSLFGroupShape) slide.getShapes().get(0);
+            assertEquals(group.getShapes().size(), 2);
+            XSLFAutoShape oval = (XSLFAutoShape) group.getShapes().get(0);
+            XSLFAutoShape arrow = (XSLFAutoShape) group.getShapes().get(1);
+            assertNull(oval.getFillColor());
+            assertNull(arrow.getFillColor());
+        }
+    }
 }

Added: poi/trunk/test-data/slideshow/63200.pptx
URL: http://svn.apache.org/viewvc/poi/trunk/test-data/slideshow/63200.pptx?rev=1854639&view=auto
==============================================================================
Binary files poi/trunk/test-data/slideshow/63200.pptx (added) and poi/trunk/test-data/slideshow/63200.pptx Sat Mar  2 12:28:19 2019 differ



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org