[英]NullPointerException while trying to delete in JIRA using groovy script runner
I am very new to groovy script runner and I have been trying to delete a field in JIRA but I always get NullPointerException. 我是groovy脚本运行器的新手,我一直在尝试删除JIRA中的一个字段,但我总是得到NullPointerException。
I do understand what NullPointerMeans and I have read multiple posts online and on atlassian but nothing has helped. 我确实理解NullPointerMeans和我在网上和atlassian上阅读了多个帖子,但没有任何帮助。
Any idea / help is appreciated on how I can achieve this 我对如何实现这一点表示赞赏
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.fields.CustomField
import org.apache.log4j.Logger;
import org.apache.log4j.Level;
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager();
CustomField customField_toDelete = customFieldManager.getCustomFieldObject("12345")
customFieldManager.removeCustomField(customField_toDelete);
Stacktrace 堆栈跟踪
java.lang.NullPointerException
at com.atlassian.jira.issue.managers.DefaultCustomFieldManager.removeCustomField(DefaultCustomFieldManager.java:490)
at com.atlassian.jira.issue.CustomFieldManager$removeCustomField$7.call(Unknown Source)
at Script2441.run(Script2441.groovy:20)
According to the JIRA documentation 根据JIRA文件
customFieldManager.getCustomFieldObject("12345")
Will return null if there is no customer field in JIRA with the identifier "12345", hence why 如果JIRA中没有标识符为“12345”的客户字段,则返回null ,因此原因
customFieldManager.removeCustomField(customField_toDelete)
Throws a null pointer (because customField_toDelete is null ) 抛出空指针(因为customField_toDelete为null )
If the method removeCustomField was @Nullable (ie was annotated with the Nullable annotation) then it would be ok to pass a null to the method, but since it is not annotated with the method, it throws an exception. 如果方法removeCustomField是@Nullable(即使用Nullable注释注释),则可以将null传递给方法,但由于它没有使用该方法注释,因此会抛出异常。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.