Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Delete all page comments via java api

Stefan Schiechel
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
December 19, 2017

Hi,

I want to delete all comments of a page for my plugin. My implementation only deletes the oldest.

Here's my code:

private void deleteComments(AbstractPage page) {
        List<Comment> comments = page.getComments();
        for(Comment comment : comments) {
          commentManager.removeCommentFromObject(comment.getId());
            // only removes first because event? is fired
        }
    }

 

All i found out is that the execution is interuptet after the first iteration by "SingleParameterMethodListenerInvoker".

I can't find a reason why the removeCommentFromObject method isn't invoked for all comments.

Thanks for help

1 answer

1 accepted

0 votes
Answer accepted
Stefan Schiechel
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
December 20, 2017

I've got it running!

The problem was that I tried to iterate the page-comments list directly. This failed because this list was modified by the removeCommentFromObject method, which caused a java.util.ConcurrentModificationException

The solution is to simply use a copy of the list:

List<Comment> comments = new ArrayList<>(page.getComments());

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events