poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmarkmur...@apache.org
Subject svn commit: r1772138 - in /poi: site/src/documentation/content/xdocs/ trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/ trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/ trunk/test-data/document/
Date Thu, 01 Dec 2016 02:21:56 GMT
Author: jmarkmurphy
Date: Thu Dec  1 02:21:56 2016
New Revision: 1772138

URL: http://svn.apache.org/viewvc?rev=1772138&view=rev
Log:
60329: Avoid NPE when styleid is null 

Task-Url: https://bz.apache.org/bugzilla/show_bug.cgi?id=60329

Added:
    poi/trunk/test-data/document/60329.docx   (with props)
Modified:
    poi/site/src/documentation/content/xdocs/status.xml
    poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFStyles.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFStyles.java

Modified: poi/site/src/documentation/content/xdocs/status.xml
URL: http://svn.apache.org/viewvc/poi/site/src/documentation/content/xdocs/status.xml?rev=1772138&r1=1772137&r2=1772138&view=diff
==============================================================================
--- poi/site/src/documentation/content/xdocs/status.xml (original)
+++ poi/site/src/documentation/content/xdocs/status.xml Thu Dec  1 02:21:56 2016
@@ -58,6 +58,7 @@
 
     <release version="3.16-beta2" date="2017-02-??">
       <actions>
+      	<action dev="PD" type="fix" fixes-bug="60329" module="XWPF">Added try/catch
block to swallow NPE</action>
         <action dev="PD" type="fix" fixes-bug="60370" module="XSSF">Encode some special
characters when setting title/text for validation text-boxes</action>
         <action dev="PD" type="fix" fixes-bug="60331" module="HPSF">Remove deprecated
classes - deprecate Mutable* property classes</action>
         <action dev="PD" type="fix" fixes-bug="60427" module="XSLF">Creating pictures
in PowerPoint slides requires scratchpad-jar for adding WMF images</action>

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFStyles.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFStyles.java?rev=1772138&r1=1772137&r2=1772138&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFStyles.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFStyles.java Thu Dec  1 02:21:56
2016
@@ -194,9 +194,13 @@ public class XWPFStyles extends POIXMLDo
      * @return style
      */
     public XWPFStyle getStyle(String styleID) {
-        for (XWPFStyle style : listStyle) {
-            if (style.getStyleId().equals(styleID))
-                return style;
+        for (XWPFStyle style : listStyle) {
+            try {
+                if (style.getStyleId().equals(styleID))
+                    return style;
+            } catch (NullPointerException e) {
+                // Ignore NPE
+            }
         }
         return null;
     }

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFStyles.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFStyles.java?rev=1772138&r1=1772137&r2=1772138&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFStyles.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFStyles.java Thu Dec
 1 02:21:56 2016
@@ -17,13 +17,18 @@
 
 package org.apache.poi.xwpf.usermodel;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.List;
 
-import junit.framework.TestCase;
-
 import org.apache.poi.xwpf.XWPFTestDataSamples;
+import org.junit.Test;
 import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTFonts;
 import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTLatentStyles;
 import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTLsdException;
@@ -31,7 +36,8 @@ import org.openxmlformats.schemas.wordpr
 import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTStyles;
 import org.openxmlformats.schemas.wordprocessingml.x2006.main.STStyleType;
 
-public class TestXWPFStyles extends TestCase {
+public final class TestXWPFStyles {
+    @Test
     public void testGetUsedStyles() throws IOException {
         XWPFDocument sampleDoc = XWPFTestDataSamples.openSampleDocument("Styles.docx");
         List<XWPFStyle> testUsedStyleList = new ArrayList<XWPFStyle>();
@@ -47,6 +53,7 @@ public class TestXWPFStyles extends Test
         assertEquals(usedStyleList, testUsedStyleList);
     }
 
+    @Test
     public void testAddStylesToDocument() throws IOException {
         XWPFDocument docOut = new XWPFDocument();
         XWPFStyles styles = docOut.createStyles();
@@ -70,6 +77,7 @@ public class TestXWPFStyles extends Test
      * Bug #52449 - We should be able to write a file containing
      * both regular and glossary styles without error
      */
+    @Test
     public void test52449() throws Exception {
         XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("52449.docx");
         XWPFStyles styles = doc.getStyles();
@@ -86,6 +94,7 @@ public class TestXWPFStyles extends Test
      * they exist only to copy xml beans to pi-ooxml-schemas.jar
      */
     @SuppressWarnings("resource")
+    @Test
     public void testLanguages() {
         XWPFDocument docOut = new XWPFDocument();
         XWPFStyles styles = docOut.createStyles();
@@ -97,6 +106,7 @@ public class TestXWPFStyles extends Test
         styles.setDefaultFonts(def);
     }
 
+    @Test
     public void testType() {
         CTStyle ctStyle = CTStyle.Factory.newInstance();
         XWPFStyle style = new XWPFStyle(ctStyle);
@@ -105,6 +115,7 @@ public class TestXWPFStyles extends Test
         assertEquals(STStyleType.PARAGRAPH, style.getType());
     }
 
+    @Test
     public void testLatentStyles() {
         CTLatentStyles latentStyles = CTLatentStyles.Factory.newInstance();
         CTLsdException ex = latentStyles.addNewLsdException();
@@ -114,6 +125,7 @@ public class TestXWPFStyles extends Test
         assertEquals(false, ls.isLatentStyle("notex1"));
     }
 
+    @Test
     public void testSetStyles_Bug57254() throws IOException {
         XWPFDocument docOut = new XWPFDocument();
         XWPFStyles styles = docOut.createStyles();
@@ -133,6 +145,7 @@ public class TestXWPFStyles extends Test
         assertTrue(styles.styleExist(strStyleId));
     }
 
+    @Test
     public void testEasyAccessToStyles() throws IOException {
         XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("SampleDoc.docx");
         XWPFStyles styles = doc.getStyles();
@@ -188,4 +201,22 @@ public class TestXWPFStyles extends Test
         assertEquals(11, styles.getDefaultRunStyle().getFontSize());
         assertEquals(200, styles.getDefaultParagraphStyle().getSpacingAfter());
     }
+    
+    // Bug 60329: style with missing StyleID throws NPE
+    @Test
+    public void testMissingStyleId() throws IOException {
+        XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("60329.docx");
+        XWPFStyles styles = doc.getStyles();
+        // Styles exist in the test document in this order, EmptyCellLayoutStyle
+        // is missing a StyleId
+        try {
+            assertNotNull(styles.getStyle("NoList"));
+            assertNull(styles.getStyle("EmptyCellLayoutStyle"));
+            assertNotNull(styles.getStyle("BalloonText"));
+        } catch (NullPointerException e) {
+            fail(e.toString());
+        }
+
+        doc.close();
+    }
 }

Added: poi/trunk/test-data/document/60329.docx
URL: http://svn.apache.org/viewvc/poi/trunk/test-data/document/60329.docx?rev=1772138&view=auto
==============================================================================
Binary file - no diff available.

Propchange: poi/trunk/test-data/document/60329.docx
------------------------------------------------------------------------------
--- svn:mime-type (added)
+++ svn:mime-type Thu Dec  1 02:21:56 2016
@@ -0,0 +1 @@
+application/vnd.openxmlformats-officedocument.wordprocessingml.document



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


Mime
View raw message