无法使用Java API创建JIRA问题

时间:2017-11-06 08:47:16

标签: java jira jira-plugin

我想用这段代码复制一个问题:

    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:执行Validator com.atlassian.jira.workflow.SkippableValidator@4b24c667时发生未知异常:根本原因:java.lang.NullPointerException ...

直到现在这个工作非常好...... 我只是在其他地方用活动对象更改了代码,但这对代码的这一部分没有影响,也没有执行(我删除了所有内容并重建它但没有任何帮助)。

1 个答案:

答案 0 :(得分:2)

查看上面的几行代码并没有给我任何线索,为什么你看到这个错误。使用Active Object API不会在问题创建API中引起任何问题。

<强> 提示: 您正在创建Jira问题而不验证参数,这些参数可以为您提供错误日志和根本原因的更好上下文。此外,它是首先验证然后调用create方法的更好方法。如下所示:

// 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

希望这会为您提供更好的背景,并帮助您解决问题。