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/10 08:18:54 UTC

svn commit: r1855139 - in /poi/trunk/src/ooxml: java/org/apache/poi/ooxml/util/ testcases/org/apache/poi/ooxml/util/

Author: centic
Date: Sun Mar 10 08:18:54 2019
New Revision: 1855139

URL: http://svn.apache.org/viewvc?rev=1855139&view=rev
Log:
Adjust test to not fail with Xerces XML Parser, fix some IDE warnings

Modified:
    poi/trunk/src/ooxml/java/org/apache/poi/ooxml/util/DocumentHelper.java
    poi/trunk/src/ooxml/java/org/apache/poi/ooxml/util/SAXHelper.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/ooxml/util/TestDocumentHelper.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/ooxml/util/TestSAXHelper.java

Modified: poi/trunk/src/ooxml/java/org/apache/poi/ooxml/util/DocumentHelper.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/ooxml/util/DocumentHelper.java?rev=1855139&r1=1855138&r2=1855139&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/ooxml/util/DocumentHelper.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/ooxml/util/DocumentHelper.java Sun Mar 10 08:18:54 2019
@@ -45,11 +45,11 @@ public final class DocumentHelper {
 
     private static class DocHelperErrorHandler implements ErrorHandler {
 
-        public void warning(SAXParseException exception) throws SAXException {
+        public void warning(SAXParseException exception) {
             printError(POILogger.WARN, exception);
         }
 
-        public void error(SAXParseException exception) throws SAXException {
+        public void error(SAXParseException exception) {
             printError(POILogger.ERROR, exception);
         }
 
@@ -111,7 +111,7 @@ public final class DocumentHelper {
         trySetXercesSecurityManager(documentBuilderFactory);
     }
 
-    private static void trySetFeature(DocumentBuilderFactory dbf, String feature, boolean enabled) {
+    private static void trySetFeature(@SuppressWarnings("SameParameterValue") DocumentBuilderFactory dbf, String feature, boolean enabled) {
         try {
             dbf.setFeature(feature, enabled);
         } catch (Exception e) {
@@ -121,7 +121,7 @@ public final class DocumentHelper {
         }
     }
     
-    private static void trySetXercesSecurityManager(DocumentBuilderFactory dbf) {
+    private static void trySetXercesSecurityManager(@SuppressWarnings("SameParameterValue") DocumentBuilderFactory dbf) {
         // Try built-in JVM one first, standalone if not
         for (String securityManagerClassName : new String[]{
                 //"com.sun.org.apache.xerces.internal.util.SecurityManager",

Modified: poi/trunk/src/ooxml/java/org/apache/poi/ooxml/util/SAXHelper.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/ooxml/util/SAXHelper.java?rev=1855139&r1=1855138&r2=1855139&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/ooxml/util/SAXHelper.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/ooxml/util/SAXHelper.java Sun Mar 10 08:18:54 2019
@@ -17,7 +17,6 @@
 
 package org.apache.poi.ooxml.util;
 
-import java.io.IOException;
 import java.io.StringReader;
 import java.lang.reflect.Method;
 import java.util.concurrent.TimeUnit;
@@ -54,13 +53,7 @@ public final class SAXHelper {
         return xmlReader;
     }
     
-    static final EntityResolver IGNORING_ENTITY_RESOLVER = new EntityResolver() {
-        @Override
-        public InputSource resolveEntity(String publicId, String systemId)
-                throws SAXException, IOException {
-            return new InputSource(new StringReader(""));
-        }
-    };
+    static final EntityResolver IGNORING_ENTITY_RESOLVER = (publicId, systemId) -> new InputSource(new StringReader(""));
     
     private static final SAXParserFactory saxFactory;
     static {
@@ -84,7 +77,8 @@ public final class SAXHelper {
         }
     }
             
-    private static void trySetSAXFeature(SAXParserFactory spf, String feature, boolean flag) {
+    private static void trySetSAXFeature(@SuppressWarnings("SameParameterValue") SAXParserFactory spf,
+                                         String feature, boolean flag) {
         try {
             spf.setFeature(feature, flag);
         } catch (Exception e) {
@@ -94,7 +88,7 @@ public final class SAXHelper {
         }
     }
 
-    private static void trySetSAXFeature(XMLReader xmlReader, String feature) {
+    private static void trySetSAXFeature(XMLReader xmlReader, @SuppressWarnings("SameParameterValue") String feature) {
         try {
             xmlReader.setFeature(feature, true);
         } catch (Exception e) {

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/ooxml/util/TestDocumentHelper.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/ooxml/util/TestDocumentHelper.java?rev=1855139&r1=1855138&r2=1855139&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/ooxml/util/TestDocumentHelper.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/ooxml/util/TestDocumentHelper.java Sun Mar 10 08:18:54 2019
@@ -18,17 +18,20 @@ package org.apache.poi.ooxml.util;
 
 import org.junit.Test;
 import org.xml.sax.InputSource;
-import org.xml.sax.XMLReader;
 
 import javax.xml.XMLConstants;
 import javax.xml.parsers.DocumentBuilder;
 import java.io.ByteArrayInputStream;
+import java.nio.charset.StandardCharsets;
 import java.util.ArrayList;
 import java.util.HashSet;
 import java.util.concurrent.CompletableFuture;
 import java.util.concurrent.TimeUnit;
 
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotSame;
+import static org.junit.Assert.assertTrue;
 
 public class TestDocumentHelper {
     @Test
@@ -37,7 +40,7 @@ public class TestDocumentHelper {
         assertNotSame(documentBuilder, DocumentHelper.newDocumentBuilder());
         assertTrue(documentBuilder.isNamespaceAware());
         assertFalse(documentBuilder.isValidating());
-        documentBuilder.parse(new InputSource(new ByteArrayInputStream("<xml></xml>".getBytes("UTF-8"))));
+        documentBuilder.parse(new InputSource(new ByteArrayInputStream("<xml></xml>".getBytes(StandardCharsets.UTF_8))));
     }
 
     @Test
@@ -45,9 +48,7 @@ public class TestDocumentHelper {
         int limit = 1000;
         ArrayList<CompletableFuture<DocumentBuilder>> futures = new ArrayList<>();
         for(int i = 0; i < limit; i++) {
-            futures.add(CompletableFuture.supplyAsync(() -> {
-                return DocumentHelper.newDocumentBuilder();
-            }));
+            futures.add(CompletableFuture.supplyAsync(DocumentHelper::newDocumentBuilder));
         }
         HashSet<DocumentBuilder> dbs = new HashSet<>();
         for(CompletableFuture<DocumentBuilder> future : futures) {

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/ooxml/util/TestSAXHelper.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/ooxml/util/TestSAXHelper.java?rev=1855139&r1=1855138&r2=1855139&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/ooxml/util/TestSAXHelper.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/ooxml/util/TestSAXHelper.java Sun Mar 10 08:18:54 2019
@@ -19,13 +19,13 @@ package org.apache.poi.ooxml.util;
 import static org.junit.Assert.*;
 
 import java.io.ByteArrayInputStream;
+import java.nio.charset.StandardCharsets;
 import java.util.ArrayList;
 import java.util.HashSet;
 import java.util.concurrent.CompletableFuture;
 import java.util.concurrent.TimeUnit;
 
 import javax.xml.XMLConstants;
-import javax.xml.parsers.DocumentBuilder;
 
 import org.junit.Test;
 import org.xml.sax.InputSource;
@@ -49,7 +49,7 @@ public class TestSAXHelper {
             // ignore exceptions from old parsers that don't support these features
             // (https://bz.apache.org/bugzilla/show_bug.cgi?id=62692)
         }
-        reader.parse(new InputSource(new ByteArrayInputStream("<xml></xml>".getBytes("UTF-8"))));
+        reader.parse(new InputSource(new ByteArrayInputStream("<xml></xml>".getBytes(StandardCharsets.UTF_8))));
     }
 
     @Test
@@ -70,7 +70,14 @@ public class TestSAXHelper {
         HashSet<XMLReader> readers = new HashSet<>();
         for(CompletableFuture<XMLReader> future : futures) {
             XMLReader reader = future.get(10, TimeUnit.SECONDS);
-            assertTrue(reader.getFeature(XMLConstants.FEATURE_SECURE_PROCESSING));
+            try {
+                assertTrue(reader.getFeature(XMLConstants.FEATURE_SECURE_PROCESSING));
+            } catch (SAXNotRecognizedException e) {
+                // can happen for older XML Parsers, e.g. we have a CI Job which runs with Xerces XML Parser
+                assertTrue("Had Exception about not-recognized SAX feature: " + e + " which is only expected" +
+                                " for Xerces XML Parser, but had parser: " + reader,
+                        reader.getClass().getName().contains("org.apache.xerces"));
+            }
             readers.add(reader);
         }
         assertEquals(limit, readers.size());



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