简体   繁体   English

尝试使用groovy脚本运行程序在JIRA中删除时出现NullPointerException

[英]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.

相关问题 尝试使用PageFactory运行我的脚本时出现“ NullPointerException” - “NullPointerException” on trying to run my script using PageFactory 从 groovy 脚本调用方法时,我在 Jenkisn 上收到 java.lang.NullPointerException - I am getting java.lang.NullPointerException on Jenkisn while calling method from groovy script 尝试使用DOM解析XML文件时获取NullPointerException - Getting a NullPointerException while trying to parse XML file using DOM 尝试使用Reflection在私有字段上调用方法时出现NullPointerException - NullPointerException while trying to invoke method on private field using Reflection 尝试使用 Hibernate 添加 ORM 层时出现 NullPointerException - NullPointerException while trying to add an ORM layer using Hibernate 尝试将setTitle()作为首选项时发生NullPointerException - NullPointerException while trying to setTitle() for Preference 使用RealM时发生NullpointerException - NullpointerException while using RealM 使用 @Autowired 时出现 NullPointerException - NullPointerException while using @Autowired 使用loadUserByUsername时发生NullPointerException - NullPointerException while using loadUserByUsername 使用Parse时发生NullPointerException - NullPointerException while using Parse
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM