Good day time dear collegues!
Developing jira plugin at the moment. So i need to comment Collection of issues. I use Comment manager and my code is pretty easy:
List<Issue> issues = results.getIssues(); Iterator<Issue> issuesIt = issues.iterator(); String gotCommentBody = "Start"; SimpleErrorCollection error = new SimpleErrorCollection(); while(issuesIt.hasNext()) { Issue issue = issuesIt.next(); if(gotCommentBody!="") { CommentManager cm = ComponentManager.getComponentInstanceOfType(CommentManager.class); Comment comment = cm.create(issue, "victor", gotCommentBody, false);// issue, author, text, throw event } }
And i've got an error here!
The first run of the cycle completes correctly and comments issue
At the second run of the cycle cm.create method throws "Cannot set or mutate an ImmutableGenericValue"
Does anyone one now what object is immutable? And why it only appears on the second run?
Thank you in advance!
Regards, Andrew.
The problem was solved. I didn't undestand the reason. May be user object wasn't saved correctly or i just needed to restructurise my code.
Hi,
Just met and solved the same issue. Adding this for the future.
The problem is your old code to try add a comment to a DocumentIssueImpl, returned by Lucene search. Jira adds a new comment, but after it Jira calls IssueImpl.setUpdated, and this operation is forbidden for read-only class.
The solution is simple - get the real issue from DB before adding a comment:
Issue issueDoc = issuesIt.next(); Issue issue = issueManager.getIssueObject(issueDoc.getId());
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Have you tried calling this after creating the comment:
cm.update(comment, false);
cm.update will attempt to persist the comment changes in the database.
Not sure why you are getting ImmutableGenericValue errors, since you are creating new comments, and not updating existing comments. (In which case you will need to call getMutableComment to get a mutable object of the comment that you can use to call update methods)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Daniel, thank you very much for your response. I tried to update comment but the result is absolutely the same:(
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I moved the CommentManager create out of the loop. Doesn't seem like you need to keep recreating it for each comment you want to create. Efficiency :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ok then how about this:
CommentManager cm = ComponentManager.getComponentInstanceOfType(CommentManager.class); while(issuesIt.hasNext()) { Issue issue = issuesIt.next(); if(gotCommentBody!="") { Comment comment = cm.create(issue, "victor", " ", false); MutableComment mComment = cm.getMutableComment(comment.getId()); mComment.setBody(gotCommentBody); cm.update(comment, false); } }
Still cannot guarantee that it works. But its worth a shot. If cant work you may try changing cm.update (mComment, false) instead. Also, not sure if that will work. ):
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you, i tried a litlle modified version of this code, now tried yours. Nothing changed. I can't underst and why the second iterarion takes comment as immutable value. And the programm stops working on this line
Comment comment = cm.create(issue,
"victor"
,
" "
,
false
);
So it's useless to change the other ones) May be i need somehow to clear smth's memmory or cache?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi, I am facing similar issue though I am able to add the comment but just getting Exception. The plugin failed exception java.lang.UnsupportedOperationException: Cannot set or mutate an ImmutableGenericValue java.lang.UnsupportedOperationException: Cannot set or mutate an ImmutableGenericValue Code Snippet: commentManager.create(issuecnt, user, comment, false); and if I try to change Issue object to MutablIssue then I get below exception and comment is also not created: The plugin failed exception java.lang.ClassCastException: com.atlassian.jira.issue.DocumentIssueImpl cannot be cast to com.atlassian.jira.issue.MutableIssue java.lang.ClassCastException: com.atlassian.jira.issue.DocumentIssueImpl cannot be cast to com.atlassian.jira.issue.MutableIssue Code Snippet: commentManager.create(((MutableIssue) issuecnt), user, comment, false);
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
And this is log
2012-12-27 18:23:07,299 QuartzWorker-0 ERROR ServiceRunner croc.apechnikov.TwitterMonitorImpl:job [atlassian.jira.service.ServiceRunner] An error occured while trying to run service 'croc.apechnikov.TwitterMonitorImpl:job'. Cannot set or mutate an ImmutableGenericValue java.lang.UnsupportedOperationException: Cannot set or mutate an ImmutableGenericValue at com.atlassian.jira.util.ofbiz.ImmutableGenericValue.set(ImmutableGenericValue.java:75) at org.ofbiz.core.entity.GenericEntity.set(GenericEntity.java:229) at com.atlassian.jira.issue.IssueImpl.updateGV(IssueImpl.java:1270) at com.atlassian.jira.issue.IssueImpl.setUpdated(IssueImpl.java:908) at com.atlassian.jira.issue.comments.DefaultCommentManager.create(DefaultCommentManager.java:209) at com.atlassian.jira.issue.comments.DefaultCommentManager.create(DefaultCommentManager.java:166) at com.atlassian.jira.issue.comments.DefaultCommentManager.create(DefaultCommentManager.java:160) at com.atlassian.jira.issue.comments.DefaultCommentManager.create(DefaultCommentManager.java:154) at com.atlassian.jira.issue.comments.DefaultCommentManager.create(DefaultCommentManager.java:148) at croc.apechnikov.TwitterMonitorImpl.action(TwitterMonitorImpl.java:173) at croc.apechnikov.Job.execute(Job.java:29) at com.atlassian.sal.jira.scheduling.JiraPluginSchedulerService.run(JiraPluginSchedulerService.java:93) at com.atlassian.jira.service.JiraServiceContainerImpl.run(JiraServiceContainerImpl.java:61) at com.atlassian.jira.service.ServiceRunner.execute(ServiceRunner.java:47) at org.quartz.core.JobRunShell.run(JobRunShell.java:195) at com.atlassian.multitenant.quartz.MultiTenantThreadPool$MultiTenantRunnable.run(MultiTenantThreadPool.java:72) at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:520)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.