Program: 29221
Project: 29221
Buggy source:
/** 
 * Parse and validate the given Siddhi variable and return a VariableExpressionExecutor
 * @param variable     Variable to be parsed
 * @param metaEvent    Meta event used to collect execution info of stream associated with query
 * @param currentState
 * @param executorList List to hold VariableExpressionExecutors to update after query parsing  @return VariableExpressionExecutor representing given variable
 */
private static ExpressionExecutor parseVariable(Variable variable,MetaComplexEvent metaEvent,int currentState,List<VariableExpressionExecutor> executorList,int defaultStreamEventIndex){
  String attributeName=variable.getAttributeName();
  int[] eventPosition=new int[2];
  if (variable.getStreamIndex() != null) {
    eventPosition[STREAM_EVENT_INDEX]=variable.getStreamIndex();
  }
 else {
    eventPosition[STREAM_EVENT_INDEX]=defaultStreamEventIndex;
  }
  if (metaEvent instanceof MetaStreamEvent) {
    MetaStreamEvent metaStreamEvent=(MetaStreamEvent)metaEvent;
    AbstractDefinition abstractDefinition;
    Attribute.Type type;
    if (currentState == HAVING_STATE) {
      abstractDefinition=metaStreamEvent.getOutputStreamDefinition();
      type=abstractDefinition.getAttributeType(attributeName);
      eventPosition[STREAM_EVENT_CHAIN_INDEX]=HAVING_STATE;
    }
 else {
      abstractDefinition=metaStreamEvent.getInputDefinition();
      eventPosition[STREAM_EVENT_CHAIN_INDEX]=UNKNOWN_STATE;
      type=abstractDefinition.getAttributeType(attributeName);
      ((MetaStreamEvent)metaEvent).addData(new Attribute(attributeName,type));
    }
    VariableExpressionExecutor variableExpressionExecutor=new VariableExpressionExecutor(new Attribute(attributeName,type),eventPosition[STREAM_EVENT_CHAIN_INDEX],eventPosition[STREAM_EVENT_INDEX]);
    if (executorList != null) {
      executorList.add(variableExpressionExecutor);
    }
    return variableExpressionExecutor;
  }
 else {
    MetaStateEvent metaStateEvent=(MetaStateEvent)metaEvent;
    Attribute.Type type=null;
    AbstractDefinition definition=null;
    String firstInput=null;
    if (variable.getStreamId() == null) {
      MetaStreamEvent[] metaStreamEvents=metaStateEvent.getMetaStreamEvents();
      if (currentState == HAVING_STATE) {
        definition=metaStateEvent.getOutputStreamDefinition();
        try {
          type=definition.getAttributeType(attributeName);
          eventPosition[STREAM_EVENT_CHAIN_INDEX]=HAVING_STATE;
        }
 catch (        AttributeNotExistException e) {
          currentState=UNKNOWN_STATE;
        }
      }
      if (currentState == UNKNOWN_STATE) {
        for (int i=0; i < metaStreamEvents.length; i++) {
          MetaStreamEvent metaStreamEvent=metaStreamEvents[i];
          definition=metaStreamEvent.getInputDefinition();
          if (type == null) {
            try {
              type=definition.getAttributeType(attributeName);
              firstInput="String_Node_Str" + definition.getId() + "String_Node_Str"+ "String_Node_Str"+ metaStreamEvent.getInputReferenceId();
              eventPosition[STREAM_EVENT_CHAIN_INDEX]=i;
            }
 catch (            AttributeNotExistException e) {
            }
          }
 else {
            try {
              definition.getAttributeType(attributeName);
              throw new ExecutionPlanValidationException(firstInput + "String_Node_Str" + definition.getId()+ "String_Node_Str"+ "String_Node_Str"+ metaStreamEvent.getInputReferenceId()+ "String_Node_Str"+ "String_Node_Str");
            }
 catch (            AttributeNotExistException e) {
            }
          }
        }
      }
 else       if (currentState >= 0) {
        MetaStreamEvent metaStreamEvent=metaStreamEvents[currentState];
        definition=metaStreamEvent.getInputDefinition();
        try {
          type=definition.getAttributeType(attributeName);
          eventPosition[STREAM_EVENT_CHAIN_INDEX]=currentState;
        }
 catch (        AttributeNotExistException e) {
          throw new ExecutionPlanValidationException(e.getMessage() + "String_Node_Str" + definition.getId()+ "String_Node_Str"+ "String_Node_Str"+ metaStreamEvent.getInputReferenceId());
        }
      }
    }
 else {
      MetaStreamEvent[] metaStreamEvents=metaStateEvent.getMetaStreamEvents();
      for (int i=0, metaStreamEventsLength=metaStreamEvents.length; i < metaStreamEventsLength; i++) {
        MetaStreamEvent metaStreamEvent=metaStreamEvents[i];
        definition=metaStreamEvent.getInputDefinition();
        if (metaStreamEvent.getInputReferenceId() == null) {
          if (definition.getId().equals(variable.getStreamId())) {
            type=definition.getAttributeType(attributeName);
            eventPosition[STREAM_EVENT_CHAIN_INDEX]=i;
            break;
          }
        }
 else {
          if (metaStreamEvent.getInputReferenceId().equals(variable.getStreamId())) {
            type=definition.getAttributeType(attributeName);
            eventPosition[STREAM_EVENT_CHAIN_INDEX]=i;
            break;
          }
        }
      }
    }
    VariableExpressionExecutor variableExpressionExecutor=new VariableExpressionExecutor(new Attribute(attributeName,type),eventPosition[STREAM_EVENT_CHAIN_INDEX],eventPosition[STREAM_EVENT_INDEX]);
    if (currentState != HAVING_STATE) {
      ((MetaStateEvent)metaEvent).getMetaStreamEvent(eventPosition[STREAM_EVENT_CHAIN_INDEX]).addData(new Attribute(attributeName,type));
    }
    if (executorList != null) {
      executorList.add(variableExpressionExecutor);
    }
    return variableExpressionExecutor;
  }
}

Fixed version (ground truth):
/** 
 * Parse and validate the given Siddhi variable and return a VariableExpressionExecutor
 * @param variable     Variable to be parsed
 * @param metaEvent    Meta event used to collect execution info of stream associated with query
 * @param currentState
 * @param executorList List to hold VariableExpressionExecutors to update after query parsing  @return VariableExpressionExecutor representing given variable
 */
private static ExpressionExecutor parseVariable(Variable variable,MetaComplexEvent metaEvent,int currentState,List<VariableExpressionExecutor> executorList,int defaultStreamEventIndex){
  String attributeName=variable.getAttributeName();
  int[] eventPosition=new int[2];
  if (variable.getStreamIndex() != null) {
    eventPosition[STREAM_EVENT_INDEX]=variable.getStreamIndex();
  }
 else {
    eventPosition[STREAM_EVENT_INDEX]=defaultStreamEventIndex;
  }
  if (metaEvent instanceof MetaStreamEvent) {
    MetaStreamEvent metaStreamEvent=(MetaStreamEvent)metaEvent;
    AbstractDefinition abstractDefinition;
    Attribute.Type type;
    if (currentState == HAVING_STATE) {
      abstractDefinition=metaStreamEvent.getOutputStreamDefinition();
      type=abstractDefinition.getAttributeType(attributeName);
      eventPosition[STREAM_EVENT_CHAIN_INDEX]=HAVING_STATE;
    }
 else {
      abstractDefinition=metaStreamEvent.getInputDefinition();
      eventPosition[STREAM_EVENT_CHAIN_INDEX]=UNKNOWN_STATE;
      type=abstractDefinition.getAttributeType(attributeName);
      ((MetaStreamEvent)metaEvent).addData(new Attribute(attributeName,type));
    }
    VariableExpressionExecutor variableExpressionExecutor=new VariableExpressionExecutor(new Attribute(attributeName,type),eventPosition[STREAM_EVENT_CHAIN_INDEX],eventPosition[STREAM_EVENT_INDEX]);
    if (((MetaStreamEvent)metaEvent).isTableEvent()) {
      variableExpressionExecutor.getPosition()[STREAM_ATTRIBUTE_TYPE_INDEX]=OUTPUT_DATA_INDEX;
      variableExpressionExecutor.getPosition()[STREAM_ATTRIBUTE_INDEX]=abstractDefinition.getAttributePosition(variableExpressionExecutor.getAttribute().getName());
    }
    if (executorList != null) {
      executorList.add(variableExpressionExecutor);
    }
    return variableExpressionExecutor;
  }
 else {
    MetaStateEvent metaStateEvent=(MetaStateEvent)metaEvent;
    Attribute.Type type=null;
    AbstractDefinition definition=null;
    String firstInput=null;
    if (variable.getStreamId() == null) {
      MetaStreamEvent[] metaStreamEvents=metaStateEvent.getMetaStreamEvents();
      if (currentState == HAVING_STATE) {
        definition=metaStateEvent.getOutputStreamDefinition();
        try {
          type=definition.getAttributeType(attributeName);
          eventPosition[STREAM_EVENT_CHAIN_INDEX]=HAVING_STATE;
        }
 catch (        AttributeNotExistException e) {
          currentState=UNKNOWN_STATE;
        }
      }
      if (currentState == UNKNOWN_STATE) {
        for (int i=0; i < metaStreamEvents.length; i++) {
          MetaStreamEvent metaStreamEvent=metaStreamEvents[i];
          definition=metaStreamEvent.getInputDefinition();
          if (type == null) {
            try {
              type=definition.getAttributeType(attributeName);
              firstInput="String_Node_Str" + definition.getId() + "String_Node_Str"+ "String_Node_Str"+ metaStreamEvent.getInputReferenceId();
              eventPosition[STREAM_EVENT_CHAIN_INDEX]=i;
            }
 catch (            AttributeNotExistException e) {
            }
          }
 else {
            try {
              definition.getAttributeType(attributeName);
              throw new ExecutionPlanValidationException(firstInput + "String_Node_Str" + definition.getId()+ "String_Node_Str"+ "String_Node_Str"+ metaStreamEvent.getInputReferenceId()+ "String_Node_Str"+ "String_Node_Str");
            }
 catch (            AttributeNotExistException e) {
            }
          }
        }
      }
 else       if (currentState >= 0) {
        MetaStreamEvent metaStreamEvent=metaStreamEvents[currentState];
        definition=metaStreamEvent.getInputDefinition();
        try {
          type=definition.getAttributeType(attributeName);
          eventPosition[STREAM_EVENT_CHAIN_INDEX]=currentState;
        }
 catch (        AttributeNotExistException e) {
          throw new ExecutionPlanValidationException(e.getMessage() + "String_Node_Str" + definition.getId()+ "String_Node_Str"+ "String_Node_Str"+ metaStreamEvent.getInputReferenceId());
        }
      }
    }
 else {
      MetaStreamEvent[] metaStreamEvents=metaStateEvent.getMetaStreamEvents();
      for (int i=0, metaStreamEventsLength=metaStreamEvents.length; i < metaStreamEventsLength; i++) {
        MetaStreamEvent metaStreamEvent=metaStreamEvents[i];
        definition=metaStreamEvent.getInputDefinition();
        if (metaStreamEvent.getInputReferenceId() == null) {
          if (definition.getId().equals(variable.getStreamId())) {
            type=definition.getAttributeType(attributeName);
            eventPosition[STREAM_EVENT_CHAIN_INDEX]=i;
            break;
          }
        }
 else {
          if (metaStreamEvent.getInputReferenceId().equals(variable.getStreamId())) {
            type=definition.getAttributeType(attributeName);
            eventPosition[STREAM_EVENT_CHAIN_INDEX]=i;
            break;
          }
        }
      }
    }
    VariableExpressionExecutor variableExpressionExecutor=new VariableExpressionExecutor(new Attribute(attributeName,type),eventPosition[STREAM_EVENT_CHAIN_INDEX],eventPosition[STREAM_EVENT_INDEX]);
    MetaStreamEvent metaStreamEvent=((MetaStateEvent)metaEvent).getMetaStreamEvent(eventPosition[STREAM_EVENT_CHAIN_INDEX]);
    if (metaStreamEvent.isTableEvent()) {
      variableExpressionExecutor.getPosition()[STREAM_ATTRIBUTE_TYPE_INDEX]=OUTPUT_DATA_INDEX;
      variableExpressionExecutor.getPosition()[STREAM_ATTRIBUTE_INDEX]=metaStreamEvent.getInputDefinition().getAttributePosition(variableExpressionExecutor.getAttribute().getName());
    }
    if (currentState != HAVING_STATE) {
      ((MetaStateEvent)metaEvent).getMetaStreamEvent(eventPosition[STREAM_EVENT_CHAIN_INDEX]).addData(new Attribute(attributeName,type));
    }
    if (executorList != null) {
      executorList.add(variableExpressionExecutor);
    }
    return variableExpressionExecutor;
  }
}