Markus Karg created BATIK-1400:
----------------------------------

             Summary: XMLResourceDescriptor.getParserProps() never closes the 
InputStream loaded from resources
                 Key: BATIK-1400
                 URL: https://issues.apache.org/jira/browse/BATIK-1400
             Project: Batik
          Issue Type: Bug
            Reporter: Markus Karg


{{org.apache.batik.util.XMLResourceDescriptor#getParserProps()}} opens an 
{{InputStream}} via {{getResourceAsStream()}} and passes it to 
{{Properties.load(is)}} without ever closing it - not even via 
{_}try-with-resources{_}. Still present on {{{}main{}}}.

{{{color:#24201d}protected static synchronized Properties getParserProps() {
    if (parserProps != null)
        return parserProps;
    parserProps = new Properties();
    try {
        Class cls = XMLResourceDescriptor.class;
        InputStream *is* = cls.getResourceAsStream(RESOURCES);
        parserProps.load({*}is{*});{color}}}

{{{color:#24201d}        // *is* is not closed here
    } catch (IOException ioe) {
        throw new MissingResourceException(ioe.getMessage(), RESOURCES, null);
    }
    return parserProps;
}{color}}}

Observed effect: application servers that monitor streams handed out by their 
class loaders report the leak. E.g. Payara Server wraps every 
{{ASURLClassLoader.getResourceAsStream()}} stream in a sentinel and warns 
(NCLS-COMUTIL-00023) when the stream is GC'd without explicit close:{{{}{}}}

_Input stream has been finalized or forced closed without being explicitly 
closed; stream instantiation reported in following stack trace_
    _at 
org.apache.batik.util.XMLResourceDescriptor.getParserProps(XMLResourceDescriptor.java:75)_
    _at 
org.apache.batik.util.XMLResourceDescriptor.getXMLParserClassName(XMLResourceDescriptor.java:94)_

{{Suggested fix:}}

{{{}{}}}{{{}try (InputStream is = 
XMLResourceDescriptor.class.getResourceAsStream(RESOURCES)) {{}}}
{{    parserProps.load(is);}}
{{}}}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to