Program: 172271
Project: 172271
Buggy source:
/** 
 * Sets Properties of Task
 * @param instance  task instance
 * @param properties  properties to set
 */
protected void setTaskProperties(TaskInstance instance,Map<QName,Serializable> properties){
  if (properties == null) {
    return;
  }
  TypeDefinition taskDef=getAnonymousTaskDefinition(getTaskDefinition(instance.getTask()));
  Map<QName,PropertyDefinition> taskProperties=taskDef.getProperties();
  Map<QName,AssociationDefinition> taskAssocs=taskDef.getAssociations();
  for (  Entry<QName,Serializable> entry : properties.entrySet()) {
    QName key=entry.getKey();
    Serializable value=entry.getValue();
    PropertyDefinition propDef=taskProperties.get(key);
    if (propDef != null) {
      if (propDef.isProtected()) {
        continue;
      }
      if (value instanceof Collection) {
        value=(Serializable)DefaultTypeConverter.INSTANCE.convert(propDef.getDataType(),(Collection)value);
      }
 else {
        value=(Serializable)DefaultTypeConverter.INSTANCE.convert(propDef.getDataType(),value);
      }
      DataTypeDefinition dataTypeDef=propDef.getDataType();
      if (dataTypeDef.getName().equals(DataTypeDefinition.NODE_REF)) {
        value=convertNodeRefs(propDef.isMultiValued(),value);
      }
      if (key.equals(WorkflowModel.PROP_DESCRIPTION)) {
        if (value != null && !(value instanceof String)) {
          throw new WorkflowException("String_Node_Str" + value + "String_Node_Str");
        }
        instance.setDescription((String)value);
        continue;
      }
      if (key.equals(WorkflowModel.PROP_DUE_DATE)) {
        if (value != null && !(value instanceof Date)) {
          throw new WorkflowException("String_Node_Str" + value + "String_Node_Str");
        }
        instance.setDueDate((Date)value);
        continue;
      }
 else       if (key.equals(WorkflowModel.PROP_PRIORITY)) {
        if (!(value instanceof Integer)) {
          throw new WorkflowException("String_Node_Str" + value + "String_Node_Str");
        }
        instance.setPriority((Integer)value);
        continue;
      }
 else       if (key.equals(WorkflowModel.PROP_COMMENT)) {
        if (!(value instanceof String)) {
          throw new WorkflowException("String_Node_Str" + value + "String_Node_Str");
        }
        final List<Comment> comments=instance.getComments();
        if (comments != null && comments.size() > 0) {
          jbpmTemplate.execute(new JbpmCallback(){
            public Object doInJbpm(            JbpmContext context){
              Session session=context.getSession();
              for (              Comment comment : comments) {
                comment.getToken().getComments().remove(comment);
                session.delete(comment);
              }
              comments.clear();
              return null;
            }
          }
);
        }
        instance.addComment((String)value);
        continue;
      }
 else       if (key.equals(ContentModel.PROP_OWNER)) {
        if (value != null && !(value instanceof String)) {
          throw new WorkflowException("String_Node_Str" + value + "String_Node_Str");
        }
        String actorId=(String)value;
        String existingActorId=instance.getActorId();
        if (existingActorId == null || !existingActorId.equals(actorId)) {
          instance.setActorId((String)value);
        }
        continue;
      }
    }
 else {
      AssociationDefinition assocDef=taskAssocs.get(key);
      if (assocDef != null) {
        value=convertNodeRefs(assocDef.isTargetMany(),value);
        if (key.equals(WorkflowModel.ASSOC_POOLED_ACTORS)) {
          String[] pooledActors=null;
          if (value instanceof JBPMNodeList[]) {
            JBPMNodeList actors=(JBPMNodeList)value;
            pooledActors=new String[actors.size()];
            int i=0;
            for (            JBPMNode actor : actors) {
              pooledActors[i++]=mapAuthorityToName(actor.getNodeRef());
            }
          }
 else           if (value instanceof JBPMNode) {
            JBPMNode node=(JBPMNode)value;
            pooledActors=new String[]{mapAuthorityToName(node.getNodeRef())};
          }
 else {
            throw new WorkflowException("String_Node_Str" + value + "String_Node_Str");
          }
          instance.setPooledActors(pooledActors);
          continue;
        }
 else         if (key.equals(WorkflowModel.ASSOC_PACKAGE)) {
          String name=mapQNameToName(key);
          JBPMNode existingWorkflowPackage=(JBPMNode)instance.getVariable(name);
          if (existingWorkflowPackage != null && value != null) {
            NodeRef newPackageNodeRef=((JBPMNode)value).getNodeRef();
            ProcessInstance processInstance=instance.getToken().getProcessInstance();
            String packageInstanceId=(String)nodeService.getProperty(newPackageNodeRef,WorkflowModel.PROP_WORKFLOW_INSTANCE_ID);
            if (packageInstanceId != null && packageInstanceId.length() > 0 && (processInstance.getId() == getJbpmId(packageInstanceId))) {
              String workflowInstanceId=createGlobalId(new Long(processInstance.getId()).toString());
              throw new WorkflowException("String_Node_Str" + newPackageNodeRef + "String_Node_Str"+ workflowInstanceId+ "String_Node_Str"+ packageInstanceId+ "String_Node_Str");
            }
          }
          if (existingWorkflowPackage == null && value != null) {
            NodeRef newPackageNodeRef=((JBPMNode)value).getNodeRef();
            ProcessInstance processInstance=instance.getToken().getProcessInstance();
            WorkflowInstance workflowInstance=createWorkflowInstance(processInstance);
            nodeService.setProperty(newPackageNodeRef,WorkflowModel.PROP_WORKFLOW_DEFINITION_ID,workflowInstance.definition.id);
            nodeService.setProperty(newPackageNodeRef,WorkflowModel.PROP_WORKFLOW_DEFINITION_NAME,workflowInstance.definition.name);
            nodeService.setProperty(newPackageNodeRef,WorkflowModel.PROP_WORKFLOW_INSTANCE_ID,workflowInstance.id);
          }
        }
      }
 else {
        if (value instanceof NodeRef) {
          value=new JBPMNode((NodeRef)value,serviceRegistry);
        }
      }
    }
    String name=mapQNameToName(key);
    instance.setVariableLocally(name,value);
  }
}

Fixed version (ground truth):
/** 
 * Sets Properties of Task
 * @param instance  task instance
 * @param properties  properties to set
 */
protected void setTaskProperties(TaskInstance instance,Map<QName,Serializable> properties){
  if (properties == null) {
    return;
  }
  TypeDefinition taskDef=getAnonymousTaskDefinition(getTaskDefinition(instance.getTask()));
  Map<QName,PropertyDefinition> taskProperties=taskDef.getProperties();
  Map<QName,AssociationDefinition> taskAssocs=taskDef.getAssociations();
  for (  Entry<QName,Serializable> entry : properties.entrySet()) {
    QName key=entry.getKey();
    Serializable value=entry.getValue();
    PropertyDefinition propDef=taskProperties.get(key);
    if (propDef != null) {
      if (propDef.isProtected()) {
        continue;
      }
      if (value instanceof Collection) {
        value=(Serializable)DefaultTypeConverter.INSTANCE.convert(propDef.getDataType(),(Collection)value);
      }
 else {
        value=(Serializable)DefaultTypeConverter.INSTANCE.convert(propDef.getDataType(),value);
      }
      DataTypeDefinition dataTypeDef=propDef.getDataType();
      if (dataTypeDef.getName().equals(DataTypeDefinition.NODE_REF)) {
        value=convertNodeRefs(propDef.isMultiValued(),value);
      }
      if (key.equals(WorkflowModel.PROP_DESCRIPTION)) {
        if (value != null && !(value instanceof String)) {
          throw new WorkflowException("String_Node_Str" + value + "String_Node_Str");
        }
        instance.setDescription((String)value);
        continue;
      }
      if (key.equals(WorkflowModel.PROP_DUE_DATE)) {
        if (value != null && !(value instanceof Date)) {
          throw new WorkflowException("String_Node_Str" + value + "String_Node_Str");
        }
        instance.setDueDate((Date)value);
        continue;
      }
 else       if (key.equals(WorkflowModel.PROP_PRIORITY)) {
        if (!(value instanceof Integer)) {
          throw new WorkflowException("String_Node_Str" + value + "String_Node_Str");
        }
        instance.setPriority((Integer)value);
        continue;
      }
 else       if (key.equals(WorkflowModel.PROP_COMMENT)) {
        if (!(value instanceof String)) {
          throw new WorkflowException("String_Node_Str" + value + "String_Node_Str");
        }
        final List<Comment> comments=instance.getComments();
        if (comments != null && comments.size() > 0) {
          jbpmTemplate.execute(new JbpmCallback(){
            public Object doInJbpm(            JbpmContext context){
              Session session=context.getSession();
              for (              Comment comment : comments) {
                comment.getToken().getComments().remove(comment);
                session.delete(comment);
              }
              comments.clear();
              return null;
            }
          }
);
        }
        instance.addComment((String)value);
        continue;
      }
 else       if (key.equals(ContentModel.PROP_OWNER)) {
        if (value != null && !(value instanceof String)) {
          throw new WorkflowException("String_Node_Str" + value + "String_Node_Str");
        }
        String actorId=(String)value;
        String existingActorId=instance.getActorId();
        if (existingActorId == null || !existingActorId.equals(actorId)) {
          instance.setActorId((String)value,false);
        }
        continue;
      }
    }
 else {
      AssociationDefinition assocDef=taskAssocs.get(key);
      if (assocDef != null) {
        value=convertNodeRefs(assocDef.isTargetMany(),value);
        if (key.equals(WorkflowModel.ASSOC_POOLED_ACTORS)) {
          String[] pooledActors=null;
          if (value instanceof JBPMNodeList[]) {
            JBPMNodeList actors=(JBPMNodeList)value;
            pooledActors=new String[actors.size()];
            int i=0;
            for (            JBPMNode actor : actors) {
              pooledActors[i++]=mapAuthorityToName(actor.getNodeRef());
            }
          }
 else           if (value instanceof JBPMNode) {
            JBPMNode node=(JBPMNode)value;
            pooledActors=new String[]{mapAuthorityToName(node.getNodeRef())};
          }
 else {
            throw new WorkflowException("String_Node_Str" + value + "String_Node_Str");
          }
          instance.setPooledActors(pooledActors);
          continue;
        }
 else         if (key.equals(WorkflowModel.ASSOC_PACKAGE)) {
          String name=mapQNameToName(key);
          JBPMNode existingWorkflowPackage=(JBPMNode)instance.getVariable(name);
          if (existingWorkflowPackage != null && value != null) {
            NodeRef newPackageNodeRef=((JBPMNode)value).getNodeRef();
            ProcessInstance processInstance=instance.getToken().getProcessInstance();
            String packageInstanceId=(String)nodeService.getProperty(newPackageNodeRef,WorkflowModel.PROP_WORKFLOW_INSTANCE_ID);
            if (packageInstanceId != null && packageInstanceId.length() > 0 && (processInstance.getId() == getJbpmId(packageInstanceId))) {
              String workflowInstanceId=createGlobalId(new Long(processInstance.getId()).toString());
              throw new WorkflowException("String_Node_Str" + newPackageNodeRef + "String_Node_Str"+ workflowInstanceId+ "String_Node_Str"+ packageInstanceId+ "String_Node_Str");
            }
          }
          if (existingWorkflowPackage == null && value != null) {
            NodeRef newPackageNodeRef=((JBPMNode)value).getNodeRef();
            ProcessInstance processInstance=instance.getToken().getProcessInstance();
            WorkflowInstance workflowInstance=createWorkflowInstance(processInstance);
            nodeService.setProperty(newPackageNodeRef,WorkflowModel.PROP_WORKFLOW_DEFINITION_ID,workflowInstance.definition.id);
            nodeService.setProperty(newPackageNodeRef,WorkflowModel.PROP_WORKFLOW_DEFINITION_NAME,workflowInstance.definition.name);
            nodeService.setProperty(newPackageNodeRef,WorkflowModel.PROP_WORKFLOW_INSTANCE_ID,workflowInstance.id);
          }
        }
      }
 else {
        if (value instanceof NodeRef) {
          value=new JBPMNode((NodeRef)value,serviceRegistry);
        }
      }
    }
    String name=mapQNameToName(key);
    instance.setVariableLocally(name,value);
  }
}