[ 
https://issues.apache.org/jira/browse/TIKA-2896?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Eamonn Saunders updated TIKA-2896:
----------------------------------
    Description: 
We have encountered a situation where the call to parser.reset() in the 
following code snippet results in a NullPointerException.
{code:java}
    private static void releaseParser(SAXParser parser) {
        try {
            parser.reset();
        } catch (UnsupportedOperationException e) {
            //ignore
        }
{code}
releaseParser() is called in the finally block of MimeTypesReader.read()
{code:java}
    public void read(InputStream stream) throws IOException, MimeTypeException {
        SAXParser parser = null;
        try {

            parser = acquireSAXParser();
            parser.parse(stream, this);
        } catch (TikaException e) {
            throw new MimeTypeException("Unable to create an XML parser", e);
        } catch (SAXException e) {
            throw new MimeTypeException("Invalid type configuration", e);
        } finally {
            releaseParser(parser);
        }
    }{code}
The parser variable will be null coming out of acquireSAXParser() if 
acquireSAXParser() is called on a thread that is interrupted (i.e. the 
InterruptedException is handled in the following code):
{code:java}
    private static SAXParser acquireSAXParser()
            throws TikaException {
        while (true) {
            SAXParser parser = null;
            try {
                READ_WRITE_LOCK.readLock().lock();
                parser = SAX_PARSERS.poll(10, TimeUnit.MILLISECONDS);
            } catch (InterruptedException e) {
                throw new TikaException("interrupted while waiting for 
SAXParser", e);
            } finally {
                READ_WRITE_LOCK.readLock().unlock();

            }
            if (parser != null) {
                return parser;
            }
        }
    }{code}
A simple fix would be to check for null before calling releaseParser() in the 
finally block.

  was:
We have encountered a situation where the call to parser.reset() in the 
following code snippet results in a NullPointerException.
{code:java}
    private static void releaseParser(SAXParser parser) {
        try {
            parser.reset();
        } catch (UnsupportedOperationException e) {
            //ignore
        }
{code}
releaseParser() called in the finally block of MimeTypesReader.read()
{code:java}
    public void read(InputStream stream) throws IOException, MimeTypeException {
        SAXParser parser = null;
        try {

            parser = acquireSAXParser();
            parser.parse(stream, this);
        } catch (TikaException e) {
            throw new MimeTypeException("Unable to create an XML parser", e);
        } catch (SAXException e) {
            throw new MimeTypeException("Invalid type configuration", e);
        } finally {
            releaseParser(parser);
        }
    }{code}
The parser variable will be null coming out of acquireSAXParser() if 
acquireSAXParser() is called on a thread that is interrupted (i.e. the 
InterruptedException is handled in the following code:
{code:java}
    private static SAXParser acquireSAXParser()
            throws TikaException {
        while (true) {
            SAXParser parser = null;
            try {
                READ_WRITE_LOCK.readLock().lock();
                parser = SAX_PARSERS.poll(10, TimeUnit.MILLISECONDS);
            } catch (InterruptedException e) {
                throw new TikaException("interrupted while waiting for 
SAXParser", e);
            } finally {
                READ_WRITE_LOCK.readLock().unlock();

            }
            if (parser != null) {
                return parser;
            }
        }
    }{code}
A simple fix would be to check for null before calling releaseParser() in the 
finally block.


> NullPointerException in MimeTypesReader.releaseParser()
> -------------------------------------------------------
>
>                 Key: TIKA-2896
>                 URL: https://issues.apache.org/jira/browse/TIKA-2896
>             Project: Tika
>          Issue Type: Bug
>          Components: mime
>    Affects Versions: 1.21
>            Reporter: Eamonn Saunders
>            Priority: Major
>
> We have encountered a situation where the call to parser.reset() in the 
> following code snippet results in a NullPointerException.
> {code:java}
>     private static void releaseParser(SAXParser parser) {
>         try {
>             parser.reset();
>         } catch (UnsupportedOperationException e) {
>             //ignore
>         }
> {code}
> releaseParser() is called in the finally block of MimeTypesReader.read()
> {code:java}
>     public void read(InputStream stream) throws IOException, 
> MimeTypeException {
>         SAXParser parser = null;
>         try {
>             parser = acquireSAXParser();
>             parser.parse(stream, this);
>         } catch (TikaException e) {
>             throw new MimeTypeException("Unable to create an XML parser", e);
>         } catch (SAXException e) {
>             throw new MimeTypeException("Invalid type configuration", e);
>         } finally {
>             releaseParser(parser);
>         }
>     }{code}
> The parser variable will be null coming out of acquireSAXParser() if 
> acquireSAXParser() is called on a thread that is interrupted (i.e. the 
> InterruptedException is handled in the following code):
> {code:java}
>     private static SAXParser acquireSAXParser()
>             throws TikaException {
>         while (true) {
>             SAXParser parser = null;
>             try {
>                 READ_WRITE_LOCK.readLock().lock();
>                 parser = SAX_PARSERS.poll(10, TimeUnit.MILLISECONDS);
>             } catch (InterruptedException e) {
>                 throw new TikaException("interrupted while waiting for 
> SAXParser", e);
>             } finally {
>                 READ_WRITE_LOCK.readLock().unlock();
>             }
>             if (parser != null) {
>                 return parser;
>             }
>         }
>     }{code}
> A simple fix would be to check for null before calling releaseParser() in the 
> finally block.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to