IssueService: fix version is null. Why

Hi I use the IssueService to get a MutableIssue. On the GUI the FixVersion is setted. But when I dubug the value is null. What I'm doing wrong?

IssueService issueService = ComponentAccessor.getIssueService();
final IssueService.IssueResult issueResult = issueService.getIssue(authenticationContext.getUser(), issueKey);
Collection<Version> fixVersions =issueResult.getIssue().getFixVersions();

And here the fixVersions  Collection is empty. 

What I'm doing wrong?

Is there a permission problem?


12 answers

0 vote
Tarun Sapra Community Champion Aug 03, 2016

If it was a permission problem then getIssue() would have been null resulting  in null pointer exception, from the docs -

" the issue will be null if the issue does not exist or the user does not have permission. "

But you don't get NPE instead you are able to call getFixVersions() method on the mutableIssue, did you try executing this script in the Script Console, and printing the results?

Yes correctly I don't have NPE, and some values are in issueResult.getIssue().

I'm sorry: of witch Script Console did you speak?

0 vote
Tarun Sapra Community Champion Aug 03, 2016

it's part of admin section of the script runner plugin, i guess you have script runner installed, using the console it becomes easier to troubleshoot issues in groovy

Ok I found it and installed it. I try now to debug a little bit. But How does this help me to find the error on Java code? And how can I Inject (in the script) ComponentAccessor and authenticationContext?

0 vote
Tarun Sapra Community Champion Aug 04, 2016

no need to authenticationContext, Component accessor can be imported easily

Ok I runn it: 

import com.atlassian.jira.component.ComponentAccessor
def issueService = ComponentAccessor.getIssueService();
def user = ComponentAccessor.jiraAuthenticationContext.user;
def issueResult = issueService.getIssue(user, "CON-2660");
def issue = issueResult.getIssue();
def fixVersions = issue.getFixVersions();
fixVersions.each {fixVersion ->"FixVersion: ${}")}

this give me a list of the Fixversion. OK. But now I have to search the error in my java code. 

What say this to me? That I go to take the Issue in a wrong way?

It's possible to install the Script runner in development mode?



0 vote
Tarun Sapra Community Champion Aug 04, 2016

HI @Heinz Wittig , were you able to solve the issue? can you share your java code in a gist file over github?

No I'm sorry I was not able to solve this issue. Gist is out of the policy right of my conpany. I can't access it (unfortunatelly). I can past the code here


The code is: 

Controller to take the action:

import .....
@Produces({ MediaType.APPLICATION_JSON })
@Consumes({ MediaType.APPLICATION_JSON })
public class PlanningIssueRestResource {
	private final Logger log = LoggerFactory.getLogger(PlanningIssueRestResource.class);
	private PlanningIssueService planningIssueService;
	private JiraAuthenticationContext authenticationContext;
	private ObjectMapper objectMapper;
	public PlanningIssueRestResource(PlanningIssueService planningIssueService,
			JiraAuthenticationContext authenticationContext) {
		this.authenticationContext = authenticationContext;
		this.planningIssueService = planningIssueService;
	public Response createSubTasks(@PathParam("issueKey") String issueKey, String subtaskString)
			throws JsonParseException, JsonMappingException, IOException, CreateException, IndexException{
		objectMapper = new ObjectMapper();
		objectMapper.configure(JsonParser.Feature.ALLOW_BACKSLASH_ESCAPING_ANY_CHARACTER, true);
		List<CpSubtaskPhase> subTaskList = objectMapper.readValue(subtaskString, objectMapper.getTypeFactory()
				.constructCollectionType(List.class, CpSubtaskPhase.class));
		HashMap<String, List<String>> results = planningIssueService.createSubTaskFrom(subTaskList,
		return Response.ok().entity(results).build();

And the PlanningIssueService:


import ......

public class PlanningIssueServiceImpl implements PlanningIssueService {
	public HashMap<String, List<String>> createSubTaskFrom(List<CpSubtaskPhase> subtaskList,
			JiraAuthenticationContext authenticationContext) throws CreateException, IndexException {
		IssueService issueService = ComponentAccessor.getIssueService();
		HashMap<String, List<String>> results = new HashMap<String, List<String>>();
		ArrayList<String> created = new ArrayList<String>();
		ArrayList<String> errors = new ArrayList<String>();
		results.put("CREATED", created);
		results.put("ERROR", errors);
		Issue issue = null;
		try {
			issue = getIssueObject(issueService, authenticationContext, subtaskList.get(0).getIssueKey());
		} catch (Exception e) {
			errors.add("ERROR - not found on the System: " + subtaskList.get(0).getIssueKey()
					+ e.getStackTrace().toString());
		for (CpSubtaskPhase subtask : subtaskList) {
			if (subtask.isChecked()) {
				try {
					created.add(createSubTask(issue, issueService, subtask, authenticationContext));
				} catch (Exception e) {
				} catch (Exception e) {
					errors.add("ERROR on create issue: " + subtask.getSummary() + e.getStackTrace().toString());
		return results;
	private String createSubTask(Issue issue, IssueService issueService, CpSubtaskPhase subTask,
			JiraAuthenticationContext authenticationContext) throws Exception {
		ApplicationUser applicationUser = authenticationContext.getUser();
		UserManager userManager = ComponentAccessor.getUserManager();
		VersionManager versionManager = ComponentAccessor.getVersionManager();
		SubTaskManager subTaskManager = ComponentAccessor.getSubTaskManager();
		IssueIndexManager issueIndexManager = ComponentAccessor.getIssueIndexManager();
		ProjectComponentManager projComponentManager = ComponentAccessor.getProjectComponentManager();
		LabelManager labelManager = ComponentAccessor.getComponent(LabelManager.class);

		//Here some actions to set the values on the subtask

		MutableIssue assignedSubtaskIssue = assignedTask.getIssue();
		subTaskManager.createSubTaskIssueLink(issue, assignedSubtaskIssue, applicationUser.getDirectoryUser());
		IssueInputParameters issueInputValues = issueService.newIssueInputParameters();
		UpdateValidationResult validateUpdate = issueService.validateUpdate(applicationUser,
				assignedSubtaskIssue.getId(), issueInputValues);
		if (!validateUpdate.isValid()) {
			throw new Exception(validateUpdate);
		IssueResult update = issueService.update(applicationUser, validateUpdate);
		if (!update.isValid()) {
			throw new Exception(update);
		MutableIssue componentUpdateSubTask = update.getIssue();
		return "Created issue: " + componentUpdateSubTask.getSummary();
	public Issue getIssueObject(IssueService issueService, JiraAuthenticationContext authenticationContext,
			String issueKey) throws Exception {
		final IssueService.IssueResult issueResult = issueService.getIssue(authenticationContext.getUser(), issueKey);
		//Already here I have an empty fixVersion collection (by debugging)
		if (!issueResult.isValid()) {
			throw new Exception(issueResult);
		return issueResult.getIssue();

Any suggestions?




0 vote
Steven Behnke Community Champion Aug 05, 2016

I labeled your question so that Adaptavist can find it. You need to label your question with the add-on in question otherwise the proper people cannot find it.

tank you Steven smile

0 vote

This doesn't seem like a ScriptRunner issue but you can use the IssueManager to get the issue:

import com.atlassian.jira.component.ComponentAccessor

def issueManager = ComponentAccessor.getIssueManager()

def issue = issueManager.getIssueObject(issueKey)

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
Bridget Sauer
Published Thursday in Marketplace Apps

Calling all developers––You're invited to Atlas Camp 2018

 Atlas Camp   is our developer event which will take place in Barcelona, Spain  from the 6th -7th of   September . This is a great opportunity to meet other developers and get n...

77 views 0 5
Read article

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