Source:
<code>public long addOutputContent(long taskId, Map<String, Object> params) { Task task = persistenceContext.findTask(taskId); loadTaskVariables(task); long outputContentId = task.getTaskData().getOutputContentId(); Content outputContent = persistenceContext.findContent(outputContentId); Map<String, Object> initialContent = new HashMap<>(); long contentId = -1; if (outputContent == null) { ContentMarshallerContext context = getMarshallerContext(task); ContentData outputContentData = ContentMarshallerHelper.marshal(task, params, context.getEnvironment()); Content content = TaskModelProvider.getFactory().newContent(); ((InternalContent) content).setContent(outputContentData.getContent()); persistenceContext.persistContent(content); persistenceContext.setOutputToTask(content, outputContentData, task); contentId = content.getId(); } else { ContentMarshallerContext context = getMarshallerContext(task); Object unmarshalledObject = ContentMarshallerHelper.unmarshall(outputContent.getContent(), context.getEnvironment(), context.getClassloader()); if(unmarshalledObject != null && unmarshalledObject instanceof Map){ initialContent.putAll((Map<String, Object>)unmarshalledObject); ((Map<String, Object>)unmarshalledObject).putAll(params); } ContentData outputContentData = ContentMarshallerHelper.marshal(task, unmarshalledObject, context.getEnvironment()); ((InternalContent)outputContent).setContent(outputContentData.getContent()); persistenceContext.persistContent(outputContent); contentId = outputContentId; } taskEventSupport.fireBeforeTaskOutputVariablesChanged(task, context, initialContent); ((InternalTaskData)task.getTaskData()).setTaskOutputVariables(params); <START> <END> ((InternalTaskData)task.getTaskData()).setTaskOutputVariables(params); taskEventSupport.fireAfterTaskOutputVariablesChanged(task, context, params); persistenceContext.updateTask(task); return contentId; }</code><technical_language>This is called twice</technical_language>

Target:
public long addOutputContent(long taskId, Map<String, Object> params) { Task task = persistenceContext.findTask(taskId); loadTaskVariables(task); long outputContentId = task.getTaskData().getOutputContentId(); Content outputContent = persistenceContext.findContent(outputContentId); Map<String, Object> initialContent = new HashMap<>(); long contentId = -1; if (outputContent == null) { ContentMarshallerContext context = getMarshallerContext(task); ContentData outputContentData = ContentMarshallerHelper.marshal(task, params, context.getEnvironment()); Content content = TaskModelProvider.getFactory().newContent(); ((InternalContent) content).setContent(outputContentData.getContent()); persistenceContext.persistContent(content); persistenceContext.setOutputToTask(content, outputContentData, task); contentId = content.getId(); } else { ContentMarshallerContext context = getMarshallerContext(task); Object unmarshalledObject = ContentMarshallerHelper.unmarshall(outputContent.getContent(), context.getEnvironment(), context.getClassloader()); if(unmarshalledObject != null && unmarshalledObject instanceof Map){ initialContent.putAll((Map<String, Object>)unmarshalledObject); ((Map<String, Object>)unmarshalledObject).putAll(params); } ContentData outputContentData = ContentMarshallerHelper.marshal(task, unmarshalledObject, context.getEnvironment()); ((InternalContent)outputContent).setContent(outputContentData.getContent()); persistenceContext.persistContent(outputContent); contentId = outputContentId; } taskEventSupport.fireBeforeTaskOutputVariablesChanged(task, context, initialContent); ((InternalTaskData)task.getTaskData()).setTaskOutputVariables(params); taskEventSupport.fireAfterTaskOutputVariablesChanged(task, context, params); persistenceContext.updateTask(task); return contentId; }