Program: 119648
Project: 119648
Buggy source:
/** 
 * DOC nrousseau Comment method "getGuessQueryCommand".
 * @return
 */
private QueryGuessCommand getGuessQueryCommand(){
  IMetadataTable newRepositoryMetadata=null;
  String realTableName=null;
  String realTableId=null;
  String schemaName="String_Node_Str";
  if (elem.getPropertyValue(EParameterName.SCHEMA_TYPE.getName()).equals(EmfComponent.REPOSITORY)) {
    IElementParameter repositorySchemaTypeParameter=elem.getElementParameter(EParameterName.REPOSITORY_SCHEMA_TYPE.getName());
    if (repositorySchemaTypeParameter != null) {
      final Object value=repositorySchemaTypeParameter.getValue();
      if (elem instanceof Node) {
        String[] keySplitValues=value.toString().split("String_Node_Str");
        if (keySplitValues.length > 1) {
          String connectionId=value.toString().split("String_Node_Str")[0];
          String tableLabel=value.toString().split("String_Node_Str")[1];
          IProxyRepositoryFactory factory=ProxyRepositoryFactory.getInstance();
          Item item=null;
          try {
            IRepositoryViewObject repobj=factory.getLastVersion(connectionId);
            if (repobj != null) {
              Property property=repobj.getProperty();
              if (property != null) {
                item=property.getItem();
              }
            }
          }
 catch (          PersistenceException e) {
            ExceptionHandler.process(e);
          }
          if (item != null && item instanceof ConnectionItem) {
            Connection connection=((ConnectionItem)item).getConnection();
            for (            org.talend.core.model.metadata.builder.connection.MetadataTable table : ConnectionHelper.getTables(connection)) {
              if (table.getLabel().equals(tableLabel)) {
                IMetadataTable repositoryMetadata=ConvertionHelper.convert(table);
                realTableName=repositoryMetadata.getTableName();
                realTableId=repositoryMetadata.getId();
                break;
              }
            }
          }
        }
      }
    }
  }
  Connection repositoryConnection=null;
  boolean useExisting=false;
  IElementParameter elementParameter=elem.getElementParameter(EParameterName.USE_EXISTING_CONNECTION.name());
  if (elem instanceof Node) {
    IProcess process=((Node)elem).getProcess();
    if (elementParameter != null && Boolean.valueOf(String.valueOf(elementParameter.getValue()))) {
      String connName=(String)elem.getPropertyValue("String_Node_Str");
      for (      INode node : process.getGraphicalNodes()) {
        if (node.getElementName().equals(connName)) {
          useExisting=true;
          final Object propertyValue=node.getPropertyValue(EParameterName.REPOSITORY_PROPERTY_TYPE.getName());
          if (propertyValue != null) {
            IProxyRepositoryFactory factory=ProxyRepositoryFactory.getInstance();
            Item item=null;
            try {
              IRepositoryViewObject repobj=factory.getLastVersion(propertyValue.toString());
              if (repobj != null) {
                Property property=repobj.getProperty();
                if (property != null) {
                  item=property.getItem();
                }
              }
            }
 catch (            PersistenceException e) {
              ExceptionHandler.process(e);
            }
            if (item != null && item instanceof ConnectionItem) {
              repositoryConnection=((ConnectionItem)item).getConnection();
            }
          }
          break;
        }
      }
    }
  }
  if (!useExisting && elem.getPropertyValue(EParameterName.PROPERTY_TYPE.getName()).equals(EmfComponent.REPOSITORY)) {
    final Object propertyValue=elem.getPropertyValue(EParameterName.REPOSITORY_PROPERTY_TYPE.getName());
    if (propertyValue != null) {
      IProxyRepositoryFactory factory=ProxyRepositoryFactory.getInstance();
      Item item=null;
      try {
        IRepositoryViewObject repobj=factory.getLastVersion(propertyValue.toString());
        if (repobj != null) {
          Property property=repobj.getProperty();
          if (property != null) {
            item=property.getItem();
          }
        }
      }
 catch (      PersistenceException e) {
        ExceptionHandler.process(e);
      }
      if (item != null && item instanceof ConnectionItem) {
        repositoryConnection=((ConnectionItem)item).getConnection();
      }
    }
  }
  QueryGuessCommand cmd=null;
  INode node=null;
  if (elem instanceof INode) {
    node=(INode)elem;
  }
 else {
    node=((IConnection)elem).getSource();
  }
  List<IMetadataTable> metadataList=node.getMetadataList();
  newRepositoryMetadata=metadataList.get(0);
  if (newRepositoryMetadata.getListColumns().size() == 0 && metadataList.size() > 1) {
    newRepositoryMetadata=metadataList.get(1);
  }
  if (newRepositoryMetadata == null) {
    String schemaSelected=(String)node.getPropertyValue(EParameterName.REPOSITORY_SCHEMA_TYPE.getName());
    if (schemaSelected != null) {
    }
 else     if (newRepositoryMetadata == null) {
      MessageDialog.openWarning(new Shell(),Messages.getString("String_Node_Str"),Messages.getString("String_Node_Str"));
      return cmd;
    }
  }
  cmd=new QueryGuessCommand(node,newRepositoryMetadata,repositoryConnection);
  cmd.setMaps(dynamicProperty.getTableIdAndDbTypeMap(),dynamicProperty.getTableIdAndDbSchemaMap(),null);
  String type=getValueFromRepositoryName("String_Node_Str");
  if ("String_Node_Str".equalsIgnoreCase(type)) {
    type=EDatabaseTypeName.ORACLEFORSID.getDisplayName();
  }
  cmd.setParameters(realTableId,realTableName,type);
  return cmd;
}

Fixed version (ground truth):
/** 
 * DOC nrousseau Comment method "getGuessQueryCommand".
 * @return
 */
private QueryGuessCommand getGuessQueryCommand(){
  IMetadataTable newRepositoryMetadata=null;
  String realTableName=null;
  String realTableId=null;
  String schemaName="String_Node_Str";
  if (elem.getPropertyValue(EParameterName.SCHEMA_TYPE.getName()).equals(EmfComponent.REPOSITORY)) {
    IElementParameter repositorySchemaTypeParameter=elem.getElementParameter(EParameterName.REPOSITORY_SCHEMA_TYPE.getName());
    if (repositorySchemaTypeParameter != null) {
      final Object value=repositorySchemaTypeParameter.getValue();
      if (elem instanceof Node) {
        String[] keySplitValues=value.toString().split("String_Node_Str");
        if (keySplitValues.length > 1) {
          String connectionId=value.toString().split("String_Node_Str")[0];
          String tableLabel=value.toString().split("String_Node_Str")[1];
          IProxyRepositoryFactory factory=ProxyRepositoryFactory.getInstance();
          Item item=null;
          try {
            IRepositoryViewObject repobj=factory.getLastVersion(connectionId);
            if (repobj != null) {
              Property property=repobj.getProperty();
              if (property != null) {
                item=property.getItem();
              }
            }
          }
 catch (          PersistenceException e) {
            ExceptionHandler.process(e);
          }
          if (item != null && item instanceof ConnectionItem) {
            Connection connection=((ConnectionItem)item).getConnection();
            for (            org.talend.core.model.metadata.builder.connection.MetadataTable table : ConnectionHelper.getTables(connection)) {
              if (table.getLabel().equals(tableLabel)) {
                IMetadataTable repositoryMetadata=ConvertionHelper.convert(table);
                realTableName=repositoryMetadata.getTableName();
                realTableId=repositoryMetadata.getId();
                break;
              }
            }
          }
        }
      }
    }
  }
  Connection repositoryConnection=null;
  boolean useExisting=false;
  IElementParameter elementParameter=elem.getElementParameter(EParameterName.USE_EXISTING_CONNECTION.name());
  if (elem instanceof Node) {
    IProcess process=((Node)elem).getProcess();
    if (elementParameter != null && Boolean.valueOf(String.valueOf(elementParameter.getValue()))) {
      String connName=(String)elem.getPropertyValue("String_Node_Str");
      for (      INode node : process.getGraphicalNodes()) {
        if (node.getElementName().equals(connName)) {
          useExisting=true;
          final Object propertyValue=node.getPropertyValue(EParameterName.REPOSITORY_PROPERTY_TYPE.getName());
          if (propertyValue != null) {
            IProxyRepositoryFactory factory=ProxyRepositoryFactory.getInstance();
            Item item=null;
            try {
              IRepositoryViewObject repobj=factory.getLastVersion(propertyValue.toString());
              if (repobj != null) {
                Property property=repobj.getProperty();
                if (property != null) {
                  item=property.getItem();
                }
              }
            }
 catch (            PersistenceException e) {
              ExceptionHandler.process(e);
            }
            if (item != null && item instanceof ConnectionItem) {
              repositoryConnection=((ConnectionItem)item).getConnection();
            }
 else {
              initConnectionParameters();
              repositoryConnection=TracesConnectionUtils.createConnection(connParameters);
            }
          }
          break;
        }
      }
    }
  }
  if (!useExisting && elem.getPropertyValue(EParameterName.PROPERTY_TYPE.getName()).equals(EmfComponent.REPOSITORY)) {
    final Object propertyValue=elem.getPropertyValue(EParameterName.REPOSITORY_PROPERTY_TYPE.getName());
    if (propertyValue != null) {
      IProxyRepositoryFactory factory=ProxyRepositoryFactory.getInstance();
      Item item=null;
      try {
        IRepositoryViewObject repobj=factory.getLastVersion(propertyValue.toString());
        if (repobj != null) {
          Property property=repobj.getProperty();
          if (property != null) {
            item=property.getItem();
          }
        }
      }
 catch (      PersistenceException e) {
        ExceptionHandler.process(e);
      }
      if (item != null && item instanceof ConnectionItem) {
        repositoryConnection=((ConnectionItem)item).getConnection();
      }
    }
  }
  QueryGuessCommand cmd=null;
  INode node=null;
  if (elem instanceof INode) {
    node=(INode)elem;
  }
 else {
    node=((IConnection)elem).getSource();
  }
  List<IMetadataTable> metadataList=node.getMetadataList();
  newRepositoryMetadata=metadataList.get(0);
  if (newRepositoryMetadata.getListColumns().size() == 0 && metadataList.size() > 1) {
    newRepositoryMetadata=metadataList.get(1);
  }
  if (newRepositoryMetadata == null) {
    String schemaSelected=(String)node.getPropertyValue(EParameterName.REPOSITORY_SCHEMA_TYPE.getName());
    if (schemaSelected != null) {
    }
 else     if (newRepositoryMetadata == null) {
      MessageDialog.openWarning(new Shell(),Messages.getString("String_Node_Str"),Messages.getString("String_Node_Str"));
      return cmd;
    }
  }
  cmd=new QueryGuessCommand(node,newRepositoryMetadata,repositoryConnection);
  cmd.setMaps(dynamicProperty.getTableIdAndDbTypeMap(),dynamicProperty.getTableIdAndDbSchemaMap(),null);
  String type=getValueFromRepositoryName("String_Node_Str");
  if ("String_Node_Str".equalsIgnoreCase(type)) {
    type=EDatabaseTypeName.ORACLEFORSID.getDisplayName();
  }
  cmd.setParameters(realTableId,realTableName,type);
  return cmd;
}