mirror of https://github.com/apache/poi.git
[bug-63240] make SAXHelper.newXMLReader non-synchronized]
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1854941 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
0786ae5b57
commit
d6b5e936e9
|
@ -46,7 +46,7 @@ public final class SAXHelper {
|
||||||
/**
|
/**
|
||||||
* Creates a new SAX XMLReader, with sensible defaults
|
* Creates a new SAX XMLReader, with sensible defaults
|
||||||
*/
|
*/
|
||||||
public static synchronized XMLReader newXMLReader() throws SAXException, ParserConfigurationException {
|
public static XMLReader newXMLReader() throws SAXException, ParserConfigurationException {
|
||||||
XMLReader xmlReader = saxFactory.newSAXParser().getXMLReader();
|
XMLReader xmlReader = saxFactory.newSAXParser().getXMLReader();
|
||||||
xmlReader.setEntityResolver(IGNORING_ENTITY_RESOLVER);
|
xmlReader.setEntityResolver(IGNORING_ENTITY_RESOLVER);
|
||||||
trySetSAXFeature(xmlReader, XMLConstants.FEATURE_SECURE_PROCESSING);
|
trySetSAXFeature(xmlReader, XMLConstants.FEATURE_SECURE_PROCESSING);
|
||||||
|
|
|
@ -18,11 +18,13 @@ package org.apache.poi.ooxml.util;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.xml.sax.InputSource;
|
import org.xml.sax.InputSource;
|
||||||
|
import org.xml.sax.XMLReader;
|
||||||
|
|
||||||
import javax.xml.XMLConstants;
|
import javax.xml.XMLConstants;
|
||||||
import javax.xml.parsers.DocumentBuilder;
|
import javax.xml.parsers.DocumentBuilder;
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
@ -47,10 +49,13 @@ public class TestDocumentHelper {
|
||||||
return DocumentHelper.newDocumentBuilder();
|
return DocumentHelper.newDocumentBuilder();
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
HashSet<DocumentBuilder> dbs = new HashSet<>();
|
||||||
for(CompletableFuture<DocumentBuilder> future : futures) {
|
for(CompletableFuture<DocumentBuilder> future : futures) {
|
||||||
DocumentBuilder documentBuilder = future.get(10, TimeUnit.SECONDS);
|
DocumentBuilder documentBuilder = future.get(10, TimeUnit.SECONDS);
|
||||||
assertTrue(documentBuilder.isNamespaceAware());
|
assertTrue(documentBuilder.isNamespaceAware());
|
||||||
|
dbs.add(documentBuilder);
|
||||||
}
|
}
|
||||||
|
assertEquals(limit, dbs.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -19,8 +19,13 @@ package org.apache.poi.ooxml.util;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
|
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.XMLConstants;
|
||||||
|
import javax.xml.parsers.DocumentBuilder;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.xml.sax.InputSource;
|
import org.xml.sax.InputSource;
|
||||||
|
@ -46,4 +51,28 @@ public class TestSAXHelper {
|
||||||
}
|
}
|
||||||
reader.parse(new InputSource(new ByteArrayInputStream("<xml></xml>".getBytes("UTF-8"))));
|
reader.parse(new InputSource(new ByteArrayInputStream("<xml></xml>".getBytes("UTF-8"))));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCreatingManyXMLReaders() throws Exception {
|
||||||
|
int limit = 1000;
|
||||||
|
ArrayList<CompletableFuture<XMLReader>> futures = new ArrayList<>();
|
||||||
|
for(int i = 0; i < limit; i++) {
|
||||||
|
futures.add(CompletableFuture.supplyAsync(() -> {
|
||||||
|
try {
|
||||||
|
return SAXHelper.newXMLReader();
|
||||||
|
} catch (RuntimeException e) {
|
||||||
|
throw e;
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
HashSet<XMLReader> readers = new HashSet<>();
|
||||||
|
for(CompletableFuture<XMLReader> future : futures) {
|
||||||
|
XMLReader reader = future.get(10, TimeUnit.SECONDS);
|
||||||
|
assertTrue(reader.getFeature(XMLConstants.FEATURE_SECURE_PROCESSING));
|
||||||
|
readers.add(reader);
|
||||||
|
}
|
||||||
|
assertEquals(limit, readers.size());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue