无法使用 Java API 创建 JIRA 问题
Cannot create JIRA Issue with Java API
我想复制此代码的问题:
MutableIssue copiedIssue= ComponentAccessor.getIssueFactory().cloneIssueWithAllFields(issue);
copiedIssue.setProjectObject(project);
try {
copiedIssue=
ComponentAccessor.getIssueManager().
.getIssueObject(ComponentAccessor.getIssueManager()..createIssueObject(user,copiedIssue).getKey());
} catch (CreateException e) {
throw new RuntimeException(e);
}
...
我收到此错误消息:
...
java.lang.RuntimeException:com.atlassian.jira.workflow.WorkflowException:执行验证程序时发生未知异常 com.atlassian.jira.workflow.SkippableValidator@4b24c667:根本原因:java.lang.NullPointerException
...
到目前为止这一切都很好...
我只是在其他地方更改了带有活动对象的代码,但这对这部分代码没有影响,也没有执行(我删除了所有内容并重建了它,但没有任何帮助)。
查看上面的几行代码并没有给我任何线索,说明您为什么会看到此错误。使用活动对象 API 不会在问题创建 API 中造成任何问题。
提示:
您在没有验证参数的情况下创建 Jira 问题,这本可以为您提供更好的错误日志上下文和根本原因。此外,最好先验证然后调用创建方法。如下所示:
// First we need to validate the new issue being created
IssueInputParameters issueInputParameters = issueService.newIssueInputParameters();
// We're only going to set the summary and description. The rest are hard-coded to
// simplify this tutorial.
issueInputParameters.setSummary(req.getParameter("summary"));
issueInputParameters.setDescription(req.getParameter("description"));
// We need to set the assignee, reporter, project, and issueType...
// For assignee and reporter, we'll just use the currentUser
issueInputParameters.setAssigneeId(user.getName());
issueInputParameters.setReporterId(user.getName());
// We hard-code the project name to be the project with the TUTORIAL key
Project project = projectService.getProjectByKey(user, "TUTORIAL").getProject();
issueInputParameters.setProjectId(project.getId());
// We also hard-code the issueType to be a "bug" == 1
issueInputParameters.setIssueTypeId("1");
// Perform the validation
IssueService.CreateValidationResult result = issueService.validateCreate(user, issueInputParameters);
if (result.getErrorCollection().hasAnyErrors()) {
// If the validation fails, render the list of issues with the error
// To Do: Error handling code
} else {
// If the validation passes, redirect the user to the main issue list page
issueService.create(user, result);
resp.sendRedirect("issuecrud");
}
详细理解请参考这里的完整代码:
https://developer.atlassian.com/jiradev/jira-platform/guides/issues/tutorial-jira-issue-crud-servlet-and-issue-search
希望这能为您提供更好的背景信息并帮助您解决问题。
我想复制此代码的问题:
MutableIssue copiedIssue= ComponentAccessor.getIssueFactory().cloneIssueWithAllFields(issue);
copiedIssue.setProjectObject(project);
try {
copiedIssue=
ComponentAccessor.getIssueManager().
.getIssueObject(ComponentAccessor.getIssueManager()..createIssueObject(user,copiedIssue).getKey());
} catch (CreateException e) {
throw new RuntimeException(e);
}
... 我收到此错误消息:
... java.lang.RuntimeException:com.atlassian.jira.workflow.WorkflowException:执行验证程序时发生未知异常 com.atlassian.jira.workflow.SkippableValidator@4b24c667:根本原因:java.lang.NullPointerException ...
到目前为止这一切都很好... 我只是在其他地方更改了带有活动对象的代码,但这对这部分代码没有影响,也没有执行(我删除了所有内容并重建了它,但没有任何帮助)。
查看上面的几行代码并没有给我任何线索,说明您为什么会看到此错误。使用活动对象 API 不会在问题创建 API 中造成任何问题。
提示: 您在没有验证参数的情况下创建 Jira 问题,这本可以为您提供更好的错误日志上下文和根本原因。此外,最好先验证然后调用创建方法。如下所示:
// First we need to validate the new issue being created
IssueInputParameters issueInputParameters = issueService.newIssueInputParameters();
// We're only going to set the summary and description. The rest are hard-coded to
// simplify this tutorial.
issueInputParameters.setSummary(req.getParameter("summary"));
issueInputParameters.setDescription(req.getParameter("description"));
// We need to set the assignee, reporter, project, and issueType...
// For assignee and reporter, we'll just use the currentUser
issueInputParameters.setAssigneeId(user.getName());
issueInputParameters.setReporterId(user.getName());
// We hard-code the project name to be the project with the TUTORIAL key
Project project = projectService.getProjectByKey(user, "TUTORIAL").getProject();
issueInputParameters.setProjectId(project.getId());
// We also hard-code the issueType to be a "bug" == 1
issueInputParameters.setIssueTypeId("1");
// Perform the validation
IssueService.CreateValidationResult result = issueService.validateCreate(user, issueInputParameters);
if (result.getErrorCollection().hasAnyErrors()) {
// If the validation fails, render the list of issues with the error
// To Do: Error handling code
} else {
// If the validation passes, redirect the user to the main issue list page
issueService.create(user, result);
resp.sendRedirect("issuecrud");
}
详细理解请参考这里的完整代码: https://developer.atlassian.com/jiradev/jira-platform/guides/issues/tutorial-jira-issue-crud-servlet-and-issue-search
希望这能为您提供更好的背景信息并帮助您解决问题。