[
https://issues.apache.org/jira/browse/TIKA-2896?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16865970#comment-16865970
]
ASF GitHub Bot commented on TIKA-2896:
--------------------------------------
dannysmyda commented on pull request #274: TIKA-2896 Null check before
releasing parser in MimeTypesReader
URL: https://github.com/apache/tika/pull/274
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
> 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() 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)