]> source.dussan.org Git - poi.git/commitdiff
Try to avoid one NPE that popped up in commoncrawl-corpus tests
authorDominik Stadler <centic@apache.org>
Wed, 4 Apr 2018 19:40:54 +0000 (19:40 +0000)
committerDominik Stadler <centic@apache.org>
Wed, 4 Apr 2018 19:40:54 +0000 (19:40 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1828375 13f79535-47bb-0310-9956-ffa450edef68

src/integrationtest/org/apache/poi/stress/XSLFFileHandler.java
src/java/org/apache/poi/sl/draw/DrawShape.java
src/java/org/apache/poi/sl/draw/DrawSimpleShape.java
src/java/org/apache/poi/sl/draw/DrawTextShape.java
test-data/slideshow/ca.ubc.cs.people_~emhill_presentations_HowWeRefactor.pptx [new file with mode: 0755]

index 043d390990e7eaa97e7934aced55bc969b30deac..7aab657650d322f9dfb5aa1f4d4c06873f4fe81e 100644 (file)
@@ -66,7 +66,7 @@ public class XSLFFileHandler extends SlideShowHandler {
        @Override
     @Test
        public void test() throws Exception {
-        File file = new File("test-data/slideshow/ae.ac.uaeu.faculty_nafaachbili_GeomLec1.pptx");
+        File file = new File("test-data/slideshow/ca.ubc.cs.people_~emhill_presentations_HowWeRefactor.pptx");
                try (InputStream stream = new FileInputStream(file)) {
                        handleFile(stream, file.getPath());
                }
index 242b9d6a688ad459af7923ab5bc3f6cf83962b27..9977e667ed17be6c29df2c5b313884a5350ffaa5 100644 (file)
@@ -66,7 +66,15 @@ public class DrawShape implements Drawable {
         if (tx == null) {
             tx = new AffineTransform();
         }
-        final Rectangle2D anchor = tx.createTransformedShape(ps.getAnchor()).getBounds2D();
+
+        // we saw one document failing here, probably the format is slightly broken, but
+        // maybe better to try to handle it more gracefully
+        java.awt.Shape transformedShape = tx.createTransformedShape(ps.getAnchor());
+        if(transformedShape == null) {
+            return;
+        }
+
+        final Rectangle2D anchor = transformedShape.getBounds2D();
 
         char cmds[] = isHSLF ? new char[]{ 'h','v','r' } : new char[]{ 'r','h','v' };
         for (char ch : cmds) {
@@ -184,7 +192,7 @@ public class DrawShape implements Drawable {
         }
 
         AffineTransform tx = (AffineTransform)graphics.getRenderingHint(Drawable.GROUP_TRANSFORM);
-        if(tx != null && !tx.isIdentity()) {
+        if(tx != null && !tx.isIdentity() && tx.createTransformedShape(anchor) != null) {
             anchor = tx.createTransformedShape(anchor).getBounds2D();
         }
         return anchor;
index c5abefa4c593dc26ec86e22db658b7f88f536b22..7ed1d35da2c9ab42647793cd765feb2069169754 100644 (file)
@@ -405,6 +405,9 @@ public class DrawSimpleShape extends DrawShape {
         }
 
         Rectangle2D anchor = getAnchor(graphics, sh);
+        if(anchor == null) {
+            return lst;
+        }
         for (Path p : geom) {
 
             double w = p.getW(), h = p.getH(), scaleX = Units.toPoints(1), scaleY = scaleX;
index ed146538148b5c95df23ed1a59509024ba667491..413ab218c9461d7bd3e7c3e942e5a74c97e8a934 100644 (file)
@@ -45,6 +45,10 @@ public class DrawTextShape extends DrawSimpleShape {
         TextShape<?,?> s = getShape();
         
         Rectangle2D anchor = DrawShape.getAnchor(graphics, s);
+        if(anchor == null) {
+            return;
+        }
+
         Insets2D insets = s.getInsets();
         double x = anchor.getX() + insets.left;
         double y = anchor.getY();
diff --git a/test-data/slideshow/ca.ubc.cs.people_~emhill_presentations_HowWeRefactor.pptx b/test-data/slideshow/ca.ubc.cs.people_~emhill_presentations_HowWeRefactor.pptx
new file mode 100755 (executable)
index 0000000..544ee32
Binary files /dev/null and b/test-data/slideshow/ca.ubc.cs.people_~emhill_presentations_HowWeRefactor.pptx differ