Script throws Exception when executed as scheduled job
We have a strange problem with a workflow transition script.
Script shall run once a day. If a date in issues (custom field) has been reached, the issue shall be transitioned from waiting to working.
When it runs in the scriptrunner console, everything is fine.
When we create a custom scheduled job and set the same file as script, we have a lot of errors in the atlassian log, although the transition happens.
Tested with preview run of the scheduled job.
Once it also crashed the complete Jira instance, so we cannot use it currently 
Error message indicates something with "date formatting", but the script itself has no date processing?!
We would appreciate any help!
script:
import com.atlassian.jira.issue.IssueInputParameters
import com.atlassian.jira.issue.IssueInputParametersImpl
import com.atlassian.jira.bc.issue.IssueService
import com.atlassian.jira.component.ComponentAccessor
import org.apache.log4j.Level
import com.atlassian.jira.bc.issue.search.SearchService
import com.atlassian.jira.jql.parser.JqlQueryParser
import com.atlassian.jira.web.bean.PagerFilter
import com.atlassian.jira.issue.comments.CommentManager
def issueService = ComponentAccessor.issueService
def commentManager = ComponentAccessor.commentManager
def jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser)
def searchService = ComponentAccessor.getComponent(SearchService.class)
//log.setLevel(Level.ALL)
def wartend2bearbeitenTransitionId = 41 as Integer
def user = ComponentAccessor.jiraAuthenticationContext.loggedInUser
// Issues im Status 'Wartend'
def query = jqlQueryParser.parseQuery("project = SGABL AND status = Wartend AND Wiedervorlage <= endOfDay()")
def result = searchService.search(user, query, PagerFilter.getUnlimitedFilter())
// Vorgänge nach Bearbeiten überführen
result.getResults().each { issue ->
IssueInputParameters issueInputParameters = new IssueInputParametersImpl([:])
def validationResult = issueService.validateTransition(user, issue.id, wartend2bearbeitenTransitionId, issueInputParameters)
def errorCollection = validationResult.errorCollection
if (!errorCollection.hasAnyErrors()) {
issueService.transition(user, validationResult)
commentManager.create(issue, user, "Bot: Wiedervorlagedatum erreicht, Vorgang auf 'In Bearbeitung' gesetzt.", true)
} else {
log.error(errorCollection.errorMessages)
}
}
atlassian-jira.log:
2020-07-02 07:04:05,047+0200 http-nio-8080-exec-22 ERROR 0152M 424x18699x1 1bavjwx 130.93.1.168,10.214.22.80 /rest/scriptrunner/latest/scheduled-jobs/com.onresolve.scriptrunner.canned.jira.jobs.JiraCustomScheduledJob/preview [c.a.p.r.c.error.jersey.ThrowableExceptionMapper] Uncaught exception thrown by REST service: null
java.lang.StackOverflowError
at java.text.SimpleDateFormat.zeroPaddingNumber(SimpleDateFormat.java:1358)
at java.text.SimpleDateFormat.subFormat(SimpleDateFormat.java:1149)
at java.text.SimpleDateFormat.format(SimpleDateFormat.java:966)
at java.text.SimpleDateFormat.format(SimpleDateFormat.java:936)
at java.text.DateFormat.format(DateFormat.java:345)
at groovy.json.JsonOutput.writeDate(JsonOutput.java:363)
at groovy.json.JsonOutput.writeObject(JsonOutput.java:290)
...
at groovy.json.JsonOutput.writeObject(JsonOutput.java:332)
at groovy.json.JsonOutput.writeIterator(JsonOutput.java:486)
2020-07-02 07:04:10,858+0200 Structure-Jobs69ee99a9 Generator-Thread#17 INFO 0062D<-0062D 797x1953x1 1soiuuw 130.93.1.136,10.214.22.80 /rest/structure/2.0/poll [c.a.jira.index.MonitoringIndexWriter] [lucene-stats] flush stats: snapshotCount=23, totalCount=271, periodSec=340, flushIntervalMillis=14805, indexDirectory=/konsens/data/jira/caches/indexesV1/issues, indexWriterId=com.atlassian.jira.index.MonitoringIndexWriter@22a94360, indexDirectoryId=MMapDirectory@/konsens/data/jira/caches/indexesV1/issues lockFactory=org.apache.lucene.store.NativeFSLockFactory@5c748f9e
2020-07-02 07:04:11,039+0200 Structure-Jobs69ee99a9 Generator-Thread#17 : Generating #144 (structure:41) ERROR 0062D<-0062D 797x1953x1 1soiuuw 130.93.1.136,10.214.22.80 /rest/structure/2.0/poll [o.o.c.entity.jdbc.SQLProcessor] !!! ABANDONED SQLProcessor DETECTED !!!
This probably means that somebody forgot to close an EntityListIterator.
Connection: com.atlassian.jira.diagnostic.connection.DiagnosticConnection@32942ec4
SQL: SELECT ID, ENTITY_NAME, ENTITY_ID, PROPERTY_KEY, propertytype FROM propertyentry WHERE ENTITY_NAME=? AND ENTITY_ID=? AND PROPERTY_KEY=?
Jira version: 8.5.3
Scriptrunner version: 5.6.15.1-p5