[
https://issues.apache.org/jira/browse/LUCENE-6113?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14249030#comment-14249030
]
Shai Erera edited comment on LUCENE-6113 at 12/16/14 9:54 PM:
--------------------------------------------------------------
Why do you call manager.acquire() inside the try? I usually do it like that:
{code}
IndexSearcher searcher = manager.acquire();
try {
// do some work
} finally {
manager.release(searcher);
}
{code}
The jdocs of SearcherManager also suggest to do the same thing.
if you're calling it inside the try, you should definitely check that it's not
null before attempting to pass it to SM. That's the problem of calling it
inside the try. If you call it outside and it fails, there's nothing to release.
was (Author: shaie):
Why do you call searcher.acquire() inside the try? I usually do it like that:
IndexSearcher searcher = manager.acquire();
try {
// do some work
} finally {
manager.release(searcher);
}
The jdocs of SearcherManager also suggest to do the same thing.
if you're calling it inside the try, you should definitely check that it's not
null before attempting to pass it to SM. That's the problem of calling it
inside the try. If you call it outside and it fails, there's nothing to release.
> ReferenceManager.release uses assertion to expect argument not null, also
> expects argument to be not null
> ---------------------------------------------------------------------------------------------------------
>
> Key: LUCENE-6113
> URL: https://issues.apache.org/jira/browse/LUCENE-6113
> Project: Lucene - Core
> Issue Type: Bug
> Affects Versions: 4.10.1
> Reporter: ryan rawson
>
> A common use pattern for the Reference Manager looks like so:
> {code}
> IndexSearcher searcher = null;
> try {
> searcher = searcherManager.acquire();
> // do real work
> } finally {
> searcherManager.release(searcher);
> }
> {code}
> The problem with this code is if 'acquire' throws an exception, the finally
> block is called with a null reference for 'searcher'. There are two issues,
> one is this call release() uses assertion to check for argument validity,
> which is not recommended
> (http://docs.oracle.com/javase/8/docs/technotes/guides/language/assert.html)
> and secondly to fix this, we need to guard all calls to release with an if
> clause.
> Why not have release() be a noop if it is passed null, instead of triggering
> an NPE? It would support this API usage pattern w/o any changes on the
> behalf of users.
> Looking at the code, it appears that it is very unlikely that the acquire()
> call throws an exception.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]