我的代码在第 125 行和第 133 行级别有一个无限循环。 更具体地说,这些是线
ComponentAccessor.getIssueService().transition(mycurrentUser, myresult2)
和线
IssueService.TransitionValidationResult myresult = ComponentAccessor.getIssueService().validateTransition(mycurrentUser, issue.getId(), transitionToBeDoneInt, inputParameters);
下面是我的完整代码。任何人都知道是什么导致了这个无限循环?我已经多次查看我的代码,我真的不明白哪里出了问题。我正在使用 Jira 和 scriptrunner 作为后置函数,它应该添加新评论。这段代码中没有任何递归。它只是应该做一个过渡,就是这样,没有递归。这个错误太奇怪了,因为即使代码没有显示任何递归迹象,我也有一个无限循环。
我的代码很简单,只需要执行1次转换和写注释,我的代码不需要递归和循环。
import com.opensymphony.workflow.WorkflowContext
import com.atlassian.jira.issue.Issue;
import java.util.List;
import org.apache.log4j.Logger;
import com.atlassian.jira.issue.ModifiedValue;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.component.ComponentAccessor
import org.ofbiz.core.entity.GenericDelegator;
import com.atlassian.jira.issue.changehistory.ChangeHistoryManager;
import com.atlassian.jira.issue.history.ChangeItemBean;
import com.atlassian.jira.issue.comments.Comment
import com.atlassian.jira.workflow.JiraWorkflow
import com.atlassian.jira.workflow.WorkflowManager
import com.atlassian.jira.issue.changehistory.ChangeHistoryItem
import com.onresolve.scriptrunner.runner.util.UserMessageUtil
import com.atlassian.jira.config.SubTaskManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.link.LinkCollectionImpl;
import com.atlassian.jira.issue.link.IssueLink;
import com.atlassian.crowd.embedded.api.User;
import com.atlassian.jira.issue.comments.CommentManager;
import com.atlassian.jira.issue.link.IssueLinkManager;
import com.atlassian.jira.user.ApplicationUser;
import com.atlassian.jira.util.ErrorCollection;
import com.atlassian.jira.util.JiraUtils;
import com.atlassian.jira.workflow.JiraWorkflow;
import com.atlassian.jira.workflow.WorkflowManager;
import com.atlassian.jira.workflow.WorkflowTransitionUtil;
import com.atlassian.jira.workflow.WorkflowTransitionUtilImpl;
import com.atlassian.jira.workflow.function.issue.AbstractJiraFunctionProvider;
import com.opensymphony.module.propertyset.PropertySet;
import com.opensymphony.workflow.WorkflowException;
import com.opensymphony.workflow.loader.StepDescriptor;
import com.opensymphony.workflow.spi.SimpleStep;
import com.atlassian.jira.config.ConstantsManager
import com.atlassian.jira.workflow.ImmutableWorkflowDescriptor
import com.atlassian.jira.web.action.admin.workflow.ViewWorkflowStep
import com.opensymphony.workflow.loader.ActionDescriptor
import com.atlassian.jira.issue.IssueInputParametersImpl
import com.atlassian.jira.issue.IssueInputParameters
import com.atlassian.jira.bc.issue.IssueService.IssueValidationResult
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.workflow.WorkflowTransitionUtil
import com.atlassian.jira.workflow.WorkflowTransitionUtilFactory
import com.atlassian.jira.workflow.TransitionOptions
import com.atlassian.jira.bc.issue.IssueService
import com.atlassian.jira.bc.issue.IssueService.TransitionValidationResult
def log = Logger.getLogger("atlassian-jira.log")
log.warn("This is the last action ")
WorkflowManager workflowManager = ComponentAccessor.getWorkflowManager();
JiraWorkflow workflow = workflowManager.getWorkflow(issue);
def wfd = workflow.getDescriptor()
def actionName = wfd.getAction(transientVars["actionId"] as int).getName();
//Get worklflowname By actionId
int transitionToBeDone = transientVars["actionId"] as int;
log.warn("CAM 1 "+ transitionToBeDone)
ApplicationUser mycurrentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
log.warn("CAM 2")
log.warn("CAM 3")
int transitionToBeDoneInt = transitionToBeDone as Integer
List currentSteps = (ArrayList)transientVars.get("currentSteps");
log.warn("CAM 4 "+currentSteps)
SimpleStep simpleStep = currentSteps.get(0);
log.warn("CAM 5 "+simpleStep)
int beforeStepId = simpleStep.getStepId();
log.warn("CAM 6 "+beforeStepId)
ActionDescriptor ad = workflow.getDescriptor().getAction(transitionToBeDoneInt);
int afterStep = ad.getUnconditionalResult().getStep();
log.warn(" cam 7 "+afterStep)
log.warn( "resolved transition target last "+ComponentAccessor.workflowManager.getNextStatusIdForAction(issue , transientVars['actionId'] as int) )
targetStatus=ComponentAccessor.workflowManager.getNextStatusIdForAction(issue ,transitionToBeDoneInt)
log.warn(" cam 8")
def constantsManager = ComponentAccessor.getConstantsManager()
log.warn(" cam 9")
def statusName=constantsManager.getStatus(targetStatus).getName();
log.warn(" cam 10")
log.warn("cam transition target "+targetStatus + "status name "+statusName)
log.warn("CAM 11")
log.warn("cam 12")
log.warn("cam 13")
def mounaComment= "+++ added via workflow action "+"\""+actionName+"\"+++"
log.warn("cam 12"+mounaComment)
String content = (transientVars["comment"] +"\n"+mounaComment ) as String
log.warn("cam 13"+ content)
transientVars["comment"]= content
//inputParameters.setComment(content)
log.warn("cam 14"+ content)
log.warn("CAM 15 "+ issue.getKey())
def inputParameters = ComponentAccessor.getIssueService().newIssueInputParameters();
log.warn("CAM 16 "+ mycurrentUser+" "+issue.getId()+" "+ transitionToBeDoneInt+" "+inputParameters)
IssueService.TransitionValidationResult myresult = ComponentAccessor.getIssueService().validateTransition(mycurrentUser, issue.getId(), transitionToBeDoneInt, inputParameters);
def myresult2= myresult;
log.warn("CAM 16 "+ issue.getKey())
try {
if(myresult2.isValid()) {
log.warn("CAM 17 "+mycurrentUser+" ")
ComponentAccessor.getIssueService().transition(mycurrentUser, myresult2)
}
} catch(Exception e) {
log.warn("CAM 18 "+e)
log.warn (result.getErrorCollection().getErrors());
}
我没有测试它,但在我看来,您正在再次使用相同的转换来转换问题,这将再次执行该后处理函数,这将再次使用相同的转换转换问题,这将执行您的后处理函数再次......等等等等。 这也应该发生在同一个线程中,因此会导致 StackOverflowError,即使您的脚本没有任何递归或其他无限循环。
我很确定那里不需要您使用转换问题来转换问题的代码。您的脚本是一个 Post Function,它作为转换的最后一步发生。
transientVars['actionId']
应该给你确切的转换 ID,因此你最终会再次使用相同的转换来转换问题。
如果你只是想添加评论,那么只需要留下关于添加评论的代码,并删除所有关于转换问题的其余部分。