Creating an issue through ScriptRunner causes StackOverflowError

mnd April 6, 2020

I'm trying to create a Jira issue through a ScriptRunner Groovy script, and it keeps returning a `java.lang.StackOverflowError` response. The Jira logs show lots of lines with:

/rest/scriptrunner/latest/custom/createIssue [o.objectweb.jotm.jta] Current.getStatus()

The ScriptRunner documentation does state that calculated custom fields cannot be retrieved, or else they might throw this type of error. Although it doesn't seem the "Status" field should have this type of error.

The strange thing is that the issue gets created, so I'm guessing the error comes after the commit to save the new issue.

UPDATE:

I've tracked the issue down to trying to access the IssueResult after the create call. If I try to call "issueResult.getIssue()", or put any of this information in the response (and thereby triggering the "toString()" call), it causes the problem.

 

If it's helpful, here is the script I'm using:

createIssue(httpMethod: "GET") { MultivaluedMap queryParams, String body ->
// Set authenticated user
ApplicationUser user = ComponentAccessor.getUserManager().getUserByName("<<user.name>>")
ComponentAccessor.getJiraAuthenticationContext().setLoggedInUser(user)
Object loggedInUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

UserManager userUtil = ComponentAccessor.getUserManager()
IssueService issueService = ComponentAccessor.getIssueService()
LabelManager labelManager = ComponentManager.getComponentInstanceOfType(LabelManager.class)
JiraAuthenticationContext authenticationContext = ComponentAccessor.getJiraAuthenticationContext()
LoginService loginService = ComponentAccessor.getComponent(LoginService.class)
ConstantsManager constantsManager = ComponentAccessor.getConstantsManager()
StatusManager statusManager = ComponentAccessor.getComponent(StatusManager.class)

// Prepare to create the issue
IssueInputParameters issueInputParameters = issueService.newIssueInputParameters()

// Project
issueInputParameters.setProjectId(<<projectId>>)

// Type
issueInputParameters.setIssueTypeId(<<typeId>>)

// Summary
issueInputParameters.setSummary("Summary of issue")

// Priority
Priority priority = constantsManager.getPriorities().find { it.name == "Medium" }
issueInputParameters.setPriorityId(priority.getId())

// Status = Open (id: 1)
issueInputParameters.setStatusId("1")

// Assignee
issueInputParameters.setAssigneeId(user.getId().toString())

// Description
issueInputParameters.setDescription("Issue description")

// Reporter
issueInputParameters.setReporterId(user.getName())

// Allow default values where necessary
issueInputParameters.setApplyDefaultValuesWhenParameterNotProvided(true)

IssueResult issueResult = null
MutableIssue issue = null
// Validate issue input
log.info("IssueInputParameters: " + issueInputParameters);
CreateValidationResult createValidationResult = issueService.validateCreate(user, issueInputParameters)
Map responseMap = [:]
if (!createValidationResult.isValid()) {
log.info("Error validating issue:")
ErrorCollection errorCollection = createValidationResult.getErrorCollection()
Map<String, String> errors = errorCollection.getErrors()
for (String key : errors.keySet()) {
String value = errors.get(key)
responseMap[key] = value
log.info(" " + key + " => " + value)
}
}
else {
// Create issue
issueResult = issueService.create(user, createValidationResult)
log.info("IssueResult: " + issueResult);
issue = issueResult.getIssue()
log.info("MutableIssue: " + issue);
}

responseMap.loggedInUser = loggedInUser
responseMap.issueResult = issueResult
responseMap.issue = issue
responseMap.priority = priority
responseMap.createValidationResult = createValidationResult.isValid()

ResponseBuilder builder = Response.ok(new JsonBuilder(responseMap).toString())

builder.header("Access-Control-Allow-Origin", <<origin>>)

builder.header("Access-Control-Allow-Credentials", "true")
builder.header("Access-Control-Allow-Methods", "POST, GET, OPTIONS")
builder.header("Access-Control-Allow-Headers", "Origin")
return builder.build()
}

 

1 answer

0 votes
Hana Kučerová
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 9, 2020

Hi @mnd ,

it seems to me there could be some problems with the variable types:

  • IssueResult issueResult -> IssueService.IssueResult issueResult
  • CreateValidationResult createValidationResult -> IssueService.CreateValidationResult createValidationResult

I've tried to fix the ending part where the responseMap is created. I didn't test it, but there are no errors in my IDE now. Please try and let me know. Thank you.

Map responseMap = [:]

IssueService.CreateValidationResult createValidationResult = issueService.validateCreate(user, issueInputParameters)
if (!createValidationResult.isValid()) {
ErrorCollection errorCollection = createValidationResult.getErrorCollection()
Map<String, String> errors = errorCollection.getErrors()
for (String key : errors.keySet()) {
String value = errors.get(key)
responseMap[key] = value
}
}
IssueService.IssueResult issueResult = createValidationResult.isValid() ? issueService.create(user, createValidationResult) : null

responseMap.loggedInUser = loggedInUser
responseMap.issueResult = issueResult
responseMap.issue = issueResult?.isValid() ? issueResult?.getIssue() : null
responseMap.priority = priority
responseMap.createValidationResult = createValidationResult.isValid()

Suggest an answer

Log in or Sign up to answer