Cannot create Issue with Java API

I want to copy an issue with this code:

```
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);
}
```

I get this error Message:

```
java.lang.RuntimeException:com.atlassian.jira.workflow.WorkflowException: An unknown exception occured executing Validator com.atlassian.jira.workflow.SkippableValidator@4b24c667: root cause: java.lang.NullPointerException
```


This works very fine until now...
I just changed somerwhere else the code with active objects but this has no influence on this part of the code and is also not executed(i deleted everything and rebuild it but nothing helped).

1 answer

Hi Michael,

 

You've got a NullPointerException :

com.atlassian.jira.workflow.SkippableValidator@4b24c667: root cause: java.lang.NullPointerException

The stacktrace tell you the line where the Null Pointer is, just after this text. Take a look there.

 

I can see two mistakes in your code :

  1. There is two points after getIssueManager() :

    ComponentAccessor.getIssueManager()..createIssueObject(user,copiedIssue)
  2. The createIssueObject returns you the created issue, you don't need to get it.
copiedIssue = ComponentAccessor.getIssueManager().createIssueObject(user, copiedIssue);

           This line is enough.

 

Hope this help.

 

Best regards,

Christophe Sauvage

The Nullpointer exception is in this line:

copiedIssue=
ComponentAccessor.getIssueManager().
getIssueObject(ComponentAccessor.getIssueManager()..createIssueObject(user,copiedIssue).getKey());

 

I've tried your version but it throws the same exception.

copiedIssue=(MutableIssue) Issues.issueManager().createIssueObject(user,copiedIssue); 

 

java.lang.RuntimeException: Error copy issue CSD-1: com.atlassian.jira.workflow.WorkflowException: An unknown exception occured executing Validator com.atlassian.jira.workflow.SkippableValidator@65145c83: root cause: java.lang.NullPointerException
 at com.swql.jaeger.jira.webwork.CreateProjectAction.copyIssues(CreateProjectAction.java:233) [?:?]
 at com.swql.jaeger.jira.webwork.CreateProjectAction.doExecute(CreateProjectAction.java:88) [?:?]
 at webwork.action.ActionSupport.execute(ActionSupport.java:165) [webwork-1.4-atlassian-30.jar:?]
 at com.atlassian.jira.action.JiraActionSupport.execute(JiraActionSupport.java:63) [jira-api-7.2.2.jar:?]
 at webwork.interceptor.DefaultInterceptorChain.proceed(DefaultInterceptorChain.java:39) [webwork-1.4-atlassian-30.jar:?]
 at webwork.interceptor.NestedInterceptorChain.proceed(NestedInterceptorChain.java:31) [webwork-1.4-atlassian-30.jar:?]

 

Could it be from the mutable issue?

Any other idea?

The problem was something different, it was the user which leads to the null pointer exception. With hardcoded user "admin" it works again. 

Thank you Christophe for your help ! 

Glad you found a solution !

You're welcome !

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Julia Dillon
Posted Apr 17, 2018 in Jira

Tell us how your team runs on Jira!

Hey Atlassian Community! Today we are launching a bunch of customer stories about the amazing work teams, like Dropbox and Twilio, are doing with Jira. You can check out the stories here. The thi...

767 views 2 19
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you