We have run into an issue in our plugin where a correct jql search query returns no result.
This issue happens for several of our customers and unfortunately we can’t reproduce it in our test environment
Here is the code we’re using:
logger.debug("AdminUser: " + actorUser.getDisplayName() + "(" + actorUser.getKey() + ")");
issues = findIssuesFromJQL(actorUser, jql);
public List<Issue> findIssuesFromJQL(ApplicationUser user, String jql) {
try {
Query query = new DefaultJqlQueryParser().parseQuery(jql);
logger.debug("query: " + query.toString());
/* Get JQL-result */
jiraThreadLocalUtil.preCall();
SearchResults searchResults = searchService.search(user, query, PagerFilter.getUnlimitedFilter());
List<Issue> issues = searchResultsHelper.getResults(searchResults);
logger.debug("JQL result size: " + issues.size());
return issues;
} catch (Exception ee) {
logger.error("JQL is invalid: " + jql, ee);
} finally {
jiraThreadLocalUtil.postCall(APACHE_LOGGER);
}
return new ArrayList<>();
}
public class SearchResultsHelper {
private final BuildUtilsInfoImpl build = new BuildUtilsInfoImpl();
private Method getMethod() {
String method = build.getVersionNumbers()[0] < 8 ? "getIssues" : "getResults";
try {
return SearchResults.class.getMethod(method);
} catch (NoSuchMethodException e) {
throw new RuntimeException("Unable to find method: " + method + " in class: SearchResults", e);
}
}
public List<Issue> getResults(SearchResults searchResults) {
Method method = getMethod();
try {
return (List<Issue>) method.invoke(searchResults);
} catch(IllegalAccessException | InvocationTargetException e) {
throw new RuntimeException("Error in invoking method: " + method.getName() + " from class: SearchResults", e);
}
}
}
As far we can see from debug logs jql is valid and valid ApplicationUser is provided. But jql query returns zero results.
We tested similar query through Jira user interface and REST API - and the users get the right results.
This code is called from within our com.atlassian.scheduler.JobRunner implementation.
Every impacted customer upgraded from Jira 7.x to 8.4.1.
Are you sure that actorUser in this case has BROWSE permissions to the correct projects? It seems as though you should not be relying on a user-provided User object.
Good question, yes this is something we have checked. We had the customer log in as this user (confirmed via logs) and browse to the test issue. We also confirmed that they were able to get the test issue via the REST api while authenticating as the mentioned user.
Is the JQL query defined by users? Do they use 3rd party functions in that query?
It might be possible they’re using JQL functions that check permissions against authenticationContext instead of user that’s provided in search call (which isn’t correct, but it’s possible).
Maybe a stupid question, but is it possible that when you invoke the method getResults() which returns List<T>, that it returns a list of objects that cannot be cast into Issues for some reason? Or is it returning an empty list of results as well?
There is a similar issue happening with our JIRA instance. We are currently on JIRA 8.5.4 (Data Center). Before this, we were on JIRA 7.3.8 (non DC …JIRA Server). We have a listener, that would on every event, take the current issue key and append it to a JQL Search query. So say for example it would be ‘issuekey = xxx and status = Open’ or ‘issuekey = xxxx and status = In Progress’. Although the issue is in the correct status (i.e. just moved to that status), the results returned are 0. The results returned are 0 on both 8.5.4. and 7.3.8.
Hence when were using 7.3.8, there was a reindex method that was put in (calls IssueIndexManager), in order to re-index the issue, and find the issue in the next part of the plugin. This all worked fine in 7.3.8 and 8.5.4 DC UAT instance which has a single node. But the same code on 8.5.4 DC live instance (multi node), throws exceptions on the issueIndexManager.release() method, sometimes.
Is there perhaps another way to reindex an issue on JIRA Data Center with multiple nodes, in order to get the most recent results returned?