From ee179578e61179a0fdb7cedac632ad1b96825486 Mon Sep 17 00:00:00 2001 From: Pascal Christoph Date: Fri, 30 Aug 2024 15:38:39 +0200 Subject: [PATCH] Use XML API instead of setting parameter globally (#554) This has lesser implications. Also, some more declarations can be made "final". Thx @blackwinter. --- .../main/java/org/metafacture/xml/XmlDecoder.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/metafacture-xml/src/main/java/org/metafacture/xml/XmlDecoder.java b/metafacture-xml/src/main/java/org/metafacture/xml/XmlDecoder.java index 18d36d33..8e4be050 100644 --- a/metafacture-xml/src/main/java/org/metafacture/xml/XmlDecoder.java +++ b/metafacture-xml/src/main/java/org/metafacture/xml/XmlDecoder.java @@ -48,8 +48,8 @@ public final class XmlDecoder extends DefaultObjectPipe { private static final String SAX_PROPERTY_LEXICAL_HANDLER = "http://xml.org/sax/properties/lexical-handler"; - private XMLReader saxReader; - private final SAXParserFactory parserFactory = SAXParserFactory.newInstance(); + private static final String TOTAL_ENTITY_SIZE_LIMIT = "http://www.oracle.com/xml/jaxp/properties/totalEntitySizeLimit"; + private final XMLReader saxReader; /** * Creates an instance of {@link XmlDecoder} by obtaining a new instance of an @@ -57,6 +57,7 @@ public final class XmlDecoder extends DefaultObjectPipe { */ public XmlDecoder() { try { + final SAXParserFactory parserFactory = SAXParserFactory.newInstance(); parserFactory.setNamespaceAware(true); saxReader = parserFactory.newSAXParser().getXMLReader(); } @@ -71,14 +72,13 @@ public XmlDecoder() { * * Defaults to "50,000,000". Set to "0" to allow unlimited entities. * - * @param size the size of the allowed entities. Set to "0" if entities should be unlimited. + * @param totalEntitySizeLimit the size of the allowed entities. Set to "0" if entities should be unlimited. */ - public void setTotalEntitySizeLimit(final String size) { + public void setTotalEntitySizeLimit(final String totalEntitySizeLimit) { try { - System.setProperty("jdk.xml.totalEntitySizeLimit", size); - saxReader = parserFactory.newSAXParser().getXMLReader(); + saxReader.setProperty(TOTAL_ENTITY_SIZE_LIMIT, totalEntitySizeLimit); } - catch (final ParserConfigurationException | SAXException e) { + catch (final SAXException e) { throw new MetafactureException(e); } }