From: PJ Fanning Date: Wed, 6 Mar 2019 18:36:12 +0000 (+0000) Subject: [bug-63240] make DocumentHelper.newDocumentBuilder non-synchronized] X-Git-Tag: REL_4_1_0~53 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=0786ae5b571e62e8f19e0782dc9d6104a196ab96;p=poi.git [bug-63240] make DocumentHelper.newDocumentBuilder non-synchronized] git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1854935 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/ooxml/java/org/apache/poi/ooxml/util/DocumentHelper.java b/src/ooxml/java/org/apache/poi/ooxml/util/DocumentHelper.java index cf9fbf71ad..734f169dc1 100644 --- a/src/ooxml/java/org/apache/poi/ooxml/util/DocumentHelper.java +++ b/src/ooxml/java/org/apache/poi/ooxml/util/DocumentHelper.java @@ -86,7 +86,7 @@ public final class DocumentHelper { * @throws IllegalStateException If creating the DocumentBuilder fails, e.g. * due to {@link ParserConfigurationException}. */ - public static synchronized DocumentBuilder newDocumentBuilder() { + public static DocumentBuilder newDocumentBuilder() { try { DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); documentBuilder.setEntityResolver(SAXHelper.IGNORING_ENTITY_RESOLVER); diff --git a/src/ooxml/testcases/org/apache/poi/ooxml/util/TestDocumentHelper.java b/src/ooxml/testcases/org/apache/poi/ooxml/util/TestDocumentHelper.java index 63c6610f7e..9ffb78627a 100644 --- a/src/ooxml/testcases/org/apache/poi/ooxml/util/TestDocumentHelper.java +++ b/src/ooxml/testcases/org/apache/poi/ooxml/util/TestDocumentHelper.java @@ -22,6 +22,9 @@ import org.xml.sax.InputSource; import javax.xml.XMLConstants; import javax.xml.parsers.DocumentBuilder; import java.io.ByteArrayInputStream; +import java.util.ArrayList; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.TimeUnit; import static org.junit.Assert.*; @@ -35,6 +38,21 @@ public class TestDocumentHelper { documentBuilder.parse(new InputSource(new ByteArrayInputStream("".getBytes("UTF-8")))); } + @Test + public void testCreatingManyDocumentBuilders() throws Exception { + int limit = 1000; + ArrayList> futures = new ArrayList<>(); + for(int i = 0; i < limit; i++) { + futures.add(CompletableFuture.supplyAsync(() -> { + return DocumentHelper.newDocumentBuilder(); + })); + } + for(CompletableFuture future : futures) { + DocumentBuilder documentBuilder = future.get(10, TimeUnit.SECONDS); + assertTrue(documentBuilder.isNamespaceAware()); + } + } + @Test public void testDocumentBuilderFactory() throws Exception { try {