jira-client
jira-client copied to clipboard
method issue.getComments() returns an empty list
I'm trying to check if a comment is in a issue, using this code:
public boolean comprobarComentario(Issue issue, String cad) {
boolean ret = true;
Iterator ite;
Comment comp;
ite = issue.getComments().iterator();
while(ite.hasNext()){
comp=(Comment) ite.next();
if(comp.toString().equals(cad)){
ret=false;
}
}
return ret;
}
But it doesn´t works, it never enter in the while loop and if I make a .size() it's 0 always.
+1 . Comments list is always empty.
Greetings, @Zeeshana2z and @kairk.
Can you please check if user you are using with the client can view the comments of required issue?
Also @Zeeshana2z if you are comparing comment body to some string you should be using comp.getBody() rather than String representation of Comment object.
Regards.
well @nach-o-man im in a test jira, so I just have 1 user and thats the one im using. And about using .getBody it doesnt care because the program never enter in the while loop xD
I'm guessing this is a permissions or field configuration issue. jira-client is just iterating over the comments in the resource body. In your case it seems as though JIRA is not returning comments with the rest of the issue.
This methods returns an empty list when you retrieve the issue via a search. To avoid the issue you can implement a method to get all comments using the Jira REST API (similarly how it is implemented for getting worklogs):
public List<Comment> getAllComments() throws JiraException {
JSONObject obj;
try {
URI uri = restclient.buildURI(getBaseUri() + "issue/" + key + "/comment");
JSON json = restclient.get(uri);
obj = (JSONObject) json;
} catch (Exception ex) {
throw new JiraException("Failed to get comments for issue "
+ key, ex);
}
return Field.getComments(obj, restclient, key);
}
This fix worked for me.
+1 . Comments list is always empty.
Pull request: https://github.com/rcarz/jira-client/pull/233