Automation for Jira rule fails "java.lang.StringIndexOutOfBoundsException: begin 12, end 3, length 3" error

Platform Notice: Data Center - This article applies to Atlassian products on the Data Center platform.

Note that this knowledge base article was created for the Data Center version of the product. Data Center knowledge base articles for non-Data Center-specific features may also work for Server versions of the product, however they have not been tested. Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.

*Except Fisheye and Crucible

Summary

Automation for Jira rule fails "java.lang.StringIndexOutOfBoundsException: begin 12, end 3, length 3" error message.

Environment

Automation for Jira all versions

Diagnosis

  • The Automation for Jira rule is triggered, but not successful.
  • The "Audit Log" of the Automation for Jira just say "FAILURE". It does not notify which section of the rule failed. 
  • In the logs (atlassian-jira.log), we see the below error. The error is caused by StringIndexOutOfBoundsException: begin 12, end 3, length 3. 

    2024-07-14 10:59:19,675+0200 automation-rule-executor:thread-3 ERROR Monitor     [c.c.a.api.service.SingleRuleExecutorServiceImpl] Unexpected error executing rule with context TenantContext{environment=prod, clientKey='com.codebarrel.tenant.global', tenantId=TenantId{id='00000000-0000-0000-0000-000000bbbbbb'}}: AutomationEvent{traceId=xxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx, clientKey='com.codebarrel.tenant.global', triggerType=EVENT, type='jira:issue_created:issue_created', projectIds=[10100], timestamp=Sun Jul 14 10:59:13 CEST 2024, authorAccountId='xxxxxx', auditItemBatchId=null, payload='{"timestamp":1720947553602,"webhookEvent":"jira:issue_created","properties":[],"comment":null,"issue":{"self":"https://BASE_URL/rest/api/2/issue/xxxx","id":xxxx,"key":"TEST-11","changelog":{"startAt":0,"maxResults":0,"total":0,"histories":null},"fields":{"customfield_11111":null,"resolution":null,"customfield_xxxxx":[{"self":"https://BASE_URL/rest/api/2/customFieldOption/xxxx","value":"No","id":"xxxx","disabled":false}],"customfield_xxxx":"{}","lastViewed":null,"customfield_xxxxx":{"id":"21","name":"xxxx","_links":{"self":"https://BASE_URL/rest/servicedeskapi/request/xxxx/sla/21"},"completedCycles":[]},"customfield_xxxxx":"Active Directory service problem","labels":[],"customfield_xxxxx":null,"customfield_xxxxx":null,"customfield_xxxxx":["xxxxxx"],"aggregatetimeoriginalestimate":null,"customfield_xxxxx":null,"customfield_xxxxx":null,"issuelinks":[],"assignee":null,"components":[],"customfield_xxxxx":null,"customfield_xxxxx...', ignoreOwnEvents=true, authorAutomationAddon=false, priority=5}
    java.lang.StringIndexOutOfBoundsException: begin 12, end 3, length 3
    	at java.base/java.lang.String.checkBoundsBeginEnd(Unknown Source)
    	at java.base/java.lang.String.substring(Unknown Source)
    	at java.base/java.lang.String.substring(Unknown Source)
    	at com.codebarrel.automation.api.service.SingleRuleExecutorServiceImpl.transformErrorMapToString(SingleRuleExecutorServiceImpl.java:497)
    	at com.codebarrel.automation.api.service.SingleRuleExecutorServiceImpl.lambda$handleErrors$7(SingleRuleExecutorServiceImpl.java:490)
    	at java.base/java.util.HashMap$EntrySet.forEach(Unknown Source)
    	at com.codebarrel.automation.api.service.SingleRuleExecutorServiceImpl.lambda$handleErrors$8(SingleRuleExecutorServiceImpl.java:490)
    	at java.base/java.util.HashMap$Values.forEach(Unknown Source)
    	at java.base/java.util.Collections$UnmodifiableCollection.forEach(Unknown Source)
    	at com.codebarrel.automation.api.service.SingleRuleExecutorServiceImpl.handleErrors(SingleRuleExecutorServiceImpl.java:488)
    	at com.codebarrel.automation.api.service.SingleRuleExecutorServiceImpl.auditLogInvalidRule(SingleRuleExecutorServiceImpl.java:482)
  • If we look into the stacktrace, we see the rule is trying to send a "issue created" webhook event (webhookEvent":"jira:issue_created). The event is further making 3 REST API calls -
    • https://BASE_URL/rest/api/2/issue/xxxxx
    • https://BASE_URL/rest/servicedeskapi/request/xxxx/sla/21
    • https://BASE_URL/rest/api/2/customFieldOption/xxxx
  • We can also see references to com.codebarrel.automation.api.service.SingleRuleExecutorServiceImpl package in the logs. This could mean some API calls are being made, resulting in an error.
  • The preceding logs before StringIndexOutOfBoundsException error also show that some events related to 'ScriptRunner for Jira' plugin/module of the automation rule were getting executed.

    2024-07-14 10:59:17,919+0200 automation-rule-executor:thread-3 WARN Monitor     [c.o.scriptrunner.runner.ScriptBindingsManager] Listener: Total billable hours [h] custom field automatic update
    2024-07-14 10:59:17,919+0200 automation-rule-executor:thread-3 WARN Monitor     [c.o.scriptrunner.runner.ScriptBindingsManager] Initial event class: class com.atlassian.jira.event.issue.IssueEvent
    2024-07-14 10:59:17,920+0200 automation-rule-executor:thread-3 WARN Monitor     [c.o.scriptrunner.runner.ScriptBindingsManager] event class: class com.atlassian.jira.event.issue.IssueEvent
    2024-07-14 10:59:17,920+0200 automation-rule-executor:thread-3 WARN Monitor     [c.o.scriptrunner.runner.ScriptBindingsManager] event properties: [time:XXXXX, params:[eventsource:action, baseurl:https://BASE_URL], SEND_MAIL:sendMail, BASE_URL_PARAM_NAME:baseurl, CUSTOM_FIELDS_PARAM_NAME:com.atlassian.jira.event.issue.CUSTOM_FIELDS, WATCHERS_PARAM_NAME:com.atlassian.jira.event.issue.WATCHERS, CHANGE_HISTORY_PARAM_NAME:com.atlassian.jira.event.issue.CHANGE_HISTORY, COMMENTS_PARAM_NAME:com.atlassian.jira.event.issue.COMMENTS, issue:TEST-11, user:Monitor(monitor), worklog:null, changeGroup:[issue:xxxxx, author:monitor, created:2024-07-14 10:59:17.773, id:xxxxx], comment:null, eventTypeId:2, subtasksUpdated:true, sendMail:true, redundant:false, spanningOperation:Optional.empty, changeLog:[issue:xxxx, author:monitor, created:2024-07-14 10:59:17.773, id:xxxx], class:class com.atlassian.jira.event.issue.IssueEvent, project:Project: TEST]
    2024-07-14 10:59:17,921+0200 automation-rule-executor:thread-3 WARN Monitor     [c.o.scriptrunner.runner.ScriptBindingsManager] issue key: TEST-11
    2024-07-14 10:59:17,925+0200 automation-rule-executor:thread-3 WARN Monitor     [c.o.scriptrunner.runner.ScriptBindingsManager] formaRozliczaniaValue is EMPTY
    2024-07-14 10:59:17,925+0200 automation-rule-executor:thread-3 WARN Monitor     [c.o.scriptrunner.runner.ScriptBindingsManager] issue: TEST-11 - Time logged [h]: 0.0

Cause

When we check the automation rule, it's likely to have the Run a Script module in the rule. This is a module provided by ScriptRunner for Jira plugin. It's possible that a custom script configured in this module is making a REST API call that is resulting in the error.

Solution

  • For 'testing' purposes, take a backup of the "script" present in Run a script module of the rule, "delete" the Run a script module and save/publish the automation rule.
  • Trigger the automation rule again. We should not see StringIndexOutOfBoundsException error message.
  • This suggest the error is due to the custom script present in the "Run a script" module of the automation rule. The script present in the Run a script module is provided by ScriptRunner for Jira plugin. This is a third-party plugin provided by the vendor Adaptavist.
  • As the script is provided by third-party vendor, contact the vendor team to identify the error in the script and resolve the issue. 

    Providing support to issues related to third-party plugins fall outside the Support scope as per out Atlassian Support Offerings.


Last modified on Jan 10, 2025

Was this helpful?

Yes
No
Provide feedback about this article
Powered by Confluence and Scroll Viewport.