jira-client icon indicating copy to clipboard operation
jira-client copied to clipboard

method issue.getComments() returns an empty list

Open kairk opened this issue 9 years ago • 7 comments

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.

kairk avatar Apr 13 '16 15:04 kairk

+1 . Comments list is always empty.

Zeeshana2z avatar Apr 14 '16 05:04 Zeeshana2z

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.

nach-o-man avatar Apr 14 '16 19:04 nach-o-man

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

kairk avatar Apr 14 '16 19:04 kairk

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.

bobcarroll avatar May 30 '16 18:05 bobcarroll

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.

tess1o avatar Jul 23 '18 10:07 tess1o

+1 . Comments list is always empty.

T-baby avatar Jul 30 '18 14:07 T-baby

Pull request: https://github.com/rcarz/jira-client/pull/233

tess1o avatar Jul 30 '18 15:07 tess1o