Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
badges earned

Your Points Tracker
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Incorrect usage of JIRA/lucene search API

Hi Everybody!

In our Jira 8.3.2. we have a lot of calculated fields that, based on an issue field, perform a JQL on the rest of the projects and gather a list of issues. From that list of issues we then get some custom field values and calculate them in order to get a total value (for ex. total estimated effort for a project). The scripts are written and running using Scriptrunner v6.6.0.

Lately, we've noticed some errors in the logs when the fields are calculated:

2020-10-10 10:13:47,174 g2gcrm-69914:Cron Service ERROR anonymous [c.o.scriptrunner.customfield.GroovyCustomField] Script field failed on issue: XXXX-2127, field: Custom Field21 java.lang.IllegalStateException: Incorrect usage of JIRA/lucene search API. You can only create/use: ManagedIndexSearcher inside a context (request or Jira-Thread-Local). Check: JiraThreadLocalUtils for details.

The errors don’t appear on one of our staging environments but are present on the live instance which I assume is because the live environment is much busier and there are a lot of queries in the Lucene index.
I did some research and on the JiraThreadLocalUtil class, but unfortunately there is not much documentation to rely on.
The bit of code that I assume generates this error looks like: searchResults = null;
try {
    searchResults =, query, pagerFilter);
} catch (SearchException e) {
    return (Double) 0 ;

I saw one idea on a post about using “ThreadLocalUtil” in the loop, transforming to:

try {
try {
searchResults =, query, pagerFilter);
} catch (SearchException e) {
return (Double) 0 ;
} finally
jiraThreadLocalUtil.postCall(log, null)

However, this approach seems to break other things in Jira. I noticed some strange behavior when running filters that include the scripted fields: page formatting is off, results are not showing, "Activity" stream section is not showing, etc. 

Has anybody noticed this behavior and have any ideas on how to overcome this?


1 answer

1 accepted

0 votes
Answer accepted

I'm going to post the answer here, as with the help of Adaptavist support I resolved the issue by refactoring the code to:

try {


     searchResults =, query, pagerFilter);

} catch (SearchException e) {


    return (Double) total;

} finally {


by using methods from a different class:

import com.atlassian.jira.issue.index.ThreadLocalSearcherCache

although the documentation for this class states:

Low level lucene searcher context. You almost never want to use this. Most of the time you want: JiraThreadLocalUtils.wrap(Runnable) or JiraThreadLocalUtils.wrap(java.util.concurrent.Callable)

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Marketplace Apps & Integrations

New Cloud Apps Roundup - April 2021

Atlassian's marketplace partners have had a very productive start to 2021! Since our last roundup, our developer community has added over 160 new cloud apps to the Atlassian Marketplace to help you...

310 views 3 20
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you