Hi everybody,
I have a custom field used by an internal plugin.
These lovely custom field is a scripted custom field.
In some operation these custom filed gets errors, in log I found:
[innovalog.jmcf.fields.CalculatedTextField] CalculatedTextField: error evaluating formula of field "Commenti" of issue XXXXX:
Sourced file: inline evaluation of: `` import com.atlassian.jira.issue.comments.CommentManager; import org.joda.tim . . . '' : Typed variable declaration : at Line: 12 : in file: inline evaluation of: `` import com.atlassian.jira.issue.comments.CommentManager; import org.joda.tim . . . '' : c .getCreated ( )
Target exception: java.lang.NullPointerException: Null Pointer in Method Invocation
The script is:
<!-- @@Formula:
import com.atlassian.jira.issue.comments.CommentManager;
import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormatter;
import org.joda.time.format.DateTimeFormat;
import com.atlassian.jira.issue.comments.Comment;
StringBuilder s = new StringBuilder();
CommentManager commentManager = com.atlassian.jira.ComponentManager.getComponent(CommentManager.class);
Comment c = commentManager.getLastComment(issueObject);
DateTime datetime = new DateTime(c.getCreated().getTime());
DateTimeFormatter dtf = DateTimeFormat.forPattern("dd/MM/yyyy");
s.append(dtf.print(datetime));
s.append(" ");
s.append(c.getAuthorFullName());
s.append(" scrive: ");
s.append(System.lineSeparator());
s.append(c.getBody());
s.append(System.lineSeparator());
return s.toString();
-->
I didnt know how to fix it. Can anyone help me?
Hello,
I guess the problem is that the c variable is null, if there are no comments and that is why you have the error. Try to write like this:
<!-- @@Formula:
import com.atlassian.jira.issue.comments.CommentManager;
import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormatter;
import org.joda.time.format.DateTimeFormat;
import com.atlassian.jira.issue.comments.Comment;
StringBuilder s = new StringBuilder();
CommentManager commentManager = com.atlassian.jira.ComponentManager.getComponent(CommentManager.class);
Comment c = commentManager.getLastComment(issueObject);
DateTime datetime = new DateTime(c?.getCreated().getTime());
DateTimeFormatter dtf = DateTimeFormat.forPattern("dd/MM/yyyy");
s.append(dtf?.print(datetime));
s.append(" ");
s.append(c?.getAuthorFullName());
s.append(" scrive: ");
s.append(System.lineSeparator());
s.append(c?.getBody());
s.append(System.lineSeparator());
return s.toString();
-->
Hi Alexey,
thank you so much for your reply. I try this and let you know.
Chiara
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Alexy I tryed this but unfortunaly these didn't work. I analyzed the issues in wich we have the problem and there are issues with almost a comment.
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.