Program: 129349
Project: 129349
Buggy source:
public RepositoryViewObject cloneNewObject(){
  RepositoryViewObject object=null;
  try {
    Property connectionProperty=PropertiesFactory.eINSTANCE.createProperty();
    connectionProperty.setAuthor(getAuthor());
    connectionProperty.setCreationDate(getCreationDate());
    connectionProperty.setDescription(getDescription());
    connectionProperty.setId(getId());
    connectionProperty.setLabel(getLabel());
    connectionProperty.setModificationDate(getModificationDate());
    connectionProperty.setPurpose(getPurpose());
    connectionProperty.setStatusCode(getStatusCode());
    connectionProperty.setVersion(getVersion());
    final Item oldItem=getProperty().getItem();
    DatabaseConnectionItem newItem=null;
    if (oldItem instanceof DatabaseConnectionItem) {
      DatabaseConnectionItem item=(DatabaseConnectionItem)oldItem;
      newItem=PropertiesFactory.eINSTANCE.createDatabaseConnectionItem();
      newItem.setProperty(connectionProperty);
      ItemState state=PropertiesFactory.eINSTANCE.createItemState();
      state.setPath(oldItem.getState().getPath());
      newItem.setState(state);
      final DatabaseConnection connection=(DatabaseConnection)item.getConnection();
      DatabaseConnection conn=null;
      if (GlobalServiceRegister.getDefault().isServiceRegistered(IRepositoryService.class)) {
        IRepositoryService service=(IRepositoryService)GlobalServiceRegister.getDefault().getService(IRepositoryService.class);
        conn=service.cloneOriginalValueConnection(connection);
      }
      final QueriesConnection queries=connection.getQueries();
      QueriesConnection newQ=null;
      if (queries != null) {
        newQ=ConnectionFactory.eINSTANCE.createQueriesConnection();
        newQ.setConnection(conn);
        final List<Query> query=queries.getQuery();
        List<Query> queries2=new ArrayList<Query>();
        for (        Query query2 : query) {
          Query newQuery=ConnectionFactory.eINSTANCE.createQuery();
          newQuery.setProperties(query2.getProperties());
          newQuery.setComment(query2.getComment());
          newQuery.setDivergency(query2.isDivergency());
          newQuery.setId(query2.getId());
          newQuery.setLabel(query2.getLabel());
          newQuery.setQueries(newQ);
          newQuery.setSynchronised(query2.isSynchronised());
          newQuery.setValue(query2.getValue());
          newQuery.setContextMode(query2.isContextMode());
          queries2.add(newQuery);
        }
        newQ.getQuery().addAll(queries2);
      }
      final Set<MetadataTable> tables=ConnectionHelper.getTables(connection);
      List<MetadataTable> newTs=null;
      if (tables != null) {
        newTs=new ArrayList<MetadataTable>();
        for (        MetadataTable table : tables) {
          MetadataTable table2=ConnectionFactory.eINSTANCE.createMetadataTable();
          table2.setProperties(table.getProperties());
          table2.setComment(table.getComment());
          if (table2.getNamespace() instanceof Package) {
            Package pkg=(Package)table2.getNamespace();
            pkg.getDataManager().add(conn);
          }
          table2.setDivergency(table.isDivergency());
          table2.setId(table.getId());
          table2.setLabel(table.getLabel());
          table2.setSourceName(table.getSourceName());
          table2.setSynchronised(table.isSynchronised());
          table2.setTableType(table.getTableType());
          List<MetadataColumn> list=new ArrayList<MetadataColumn>();
          for (          MetadataColumn column : (List<MetadataColumn>)table.getColumns()) {
            MetadataColumn column2=ConnectionFactory.eINSTANCE.createMetadataColumn();
            column2.setProperties(column.getProperties());
            column2.setComment(column.getComment());
            column2.setDefaultValue(column.getDefaultValue());
            column2.setDivergency(column.isDivergency());
            column2.setId(column.getId());
            column2.setKey(column.isKey());
            column2.setLabel(column.getLabel());
            column2.setLength(column.getLength());
            column2.setNullable(column.isNullable());
            column2.setOriginalField(column.getOriginalField());
            column2.setPattern(column.getPattern());
            column2.setPrecision(column.getPrecision());
            column2.setSourceType(column.getSourceType());
            column2.setSynchronised(column.isSynchronised());
            column2.setTable(table2);
            column2.setTalendType(column.getTalendType());
            list.add(column2);
          }
          table2.getColumns().addAll(list);
          newTs.add(table2);
        }
      }
      Catalog c=(Catalog)ConnectionHelper.getPackage(conn.getSID(),(Connection)conn,Catalog.class);
      if (c != null) {
        PackageHelper.addMetadataTable(newTs,c);
        c.getOwnedElement().addAll(newTs);
      }
      conn.setQueries(newQ);
      newItem.setConnection(conn);
    }
    connectionProperty.setItem(newItem);
    object=new RepositoryViewObject(connectionProperty);
  }
 catch (  Exception e) {
    ExceptionHandler.process(e);
  }
  return object;
}

Fixed version (ground truth):
public RepositoryViewObject cloneNewObject(){
  RepositoryViewObject object=null;
  try {
    Property connectionProperty=PropertiesFactory.eINSTANCE.createProperty();
    connectionProperty.setAuthor(getAuthor());
    connectionProperty.setCreationDate(getCreationDate());
    connectionProperty.setDescription(getDescription());
    connectionProperty.setId(getId());
    connectionProperty.setLabel(getLabel());
    connectionProperty.setModificationDate(getModificationDate());
    connectionProperty.setPurpose(getPurpose());
    connectionProperty.setStatusCode(getStatusCode());
    connectionProperty.setVersion(getVersion());
    final Item oldItem=getProperty().getItem();
    DatabaseConnectionItem newItem=null;
    if (oldItem instanceof DatabaseConnectionItem) {
      DatabaseConnectionItem item=(DatabaseConnectionItem)oldItem;
      newItem=PropertiesFactory.eINSTANCE.createDatabaseConnectionItem();
      newItem.setProperty(connectionProperty);
      ItemState state=PropertiesFactory.eINSTANCE.createItemState();
      state.setPath(oldItem.getState().getPath());
      newItem.setState(state);
      final DatabaseConnection connection=(DatabaseConnection)item.getConnection();
      DatabaseConnection conn=null;
      if (GlobalServiceRegister.getDefault().isServiceRegistered(IRepositoryService.class)) {
        IRepositoryService service=(IRepositoryService)GlobalServiceRegister.getDefault().getService(IRepositoryService.class);
        conn=service.cloneOriginalValueConnection(connection);
      }
      final QueriesConnection queries=connection.getQueries();
      QueriesConnection newQ=null;
      if (queries != null) {
        newQ=ConnectionFactory.eINSTANCE.createQueriesConnection();
        newQ.setConnection(conn);
        final List<Query> query=queries.getQuery();
        List<Query> queries2=new ArrayList<Query>();
        for (        Query query2 : query) {
          Query newQuery=ConnectionFactory.eINSTANCE.createQuery();
          newQuery.setProperties(query2.getProperties());
          newQuery.setComment(query2.getComment());
          newQuery.setDivergency(query2.isDivergency());
          newQuery.setId(query2.getId());
          newQuery.setLabel(query2.getLabel());
          newQuery.setQueries(newQ);
          newQuery.setSynchronised(query2.isSynchronised());
          newQuery.setValue(query2.getValue());
          newQuery.setContextMode(query2.isContextMode());
          queries2.add(newQuery);
        }
        newQ.getQuery().addAll(queries2);
      }
      final Set<MetadataTable> tables=ConnectionHelper.getTables(connection);
      List<MetadataTable> newTs=null;
      if (tables != null) {
        newTs=new ArrayList<MetadataTable>();
        for (        MetadataTable table : tables) {
          MetadataTable table2=ConnectionFactory.eINSTANCE.createMetadataTable();
          table2.setProperties(table.getProperties());
          table2.setComment(table.getComment());
          if (table2.getNamespace() instanceof Package) {
            Package pkg=(Package)table2.getNamespace();
            pkg.getDataManager().add(conn);
          }
          table2.setDivergency(table.isDivergency());
          table2.setId(table.getId());
          table2.setLabel(table.getLabel());
          table2.setSourceName(table.getSourceName());
          table2.setSynchronised(table.isSynchronised());
          table2.setTableType(table.getTableType());
          List<MetadataColumn> list=new ArrayList<MetadataColumn>();
          for (          MetadataColumn column : table.getColumns()) {
            MetadataColumn column2=ConnectionFactory.eINSTANCE.createMetadataColumn();
            column2.setProperties(column.getProperties());
            column2.setComment(column.getComment());
            column2.setDefaultValue(column.getDefaultValue());
            column2.setDivergency(column.isDivergency());
            column2.setId(column.getId());
            column2.setKey(column.isKey());
            column2.setLabel(column.getLabel());
            column2.setLength(column.getLength());
            column2.setNullable(column.isNullable());
            column2.setOriginalField(column.getOriginalField());
            column2.setPattern(column.getPattern());
            column2.setPrecision(column.getPrecision());
            column2.setSourceType(column.getSourceType());
            column2.setSynchronised(column.isSynchronised());
            column2.setTable(table2);
            column2.setTalendType(column.getTalendType());
            list.add(column2);
          }
          table2.getColumns().addAll(list);
          newTs.add(table2);
        }
      }
      Catalog c=(Catalog)ConnectionHelper.getPackage(conn.getSID(),conn,Catalog.class);
      if (c != null) {
        PackageHelper.addMetadataTable(newTs,c);
        c.getOwnedElement().addAll(newTs);
      }
      conn.setQueries(newQ);
      newItem.setConnection(conn);
    }
    connectionProperty.setItem(newItem);
    object=new RepositoryViewObject(connectionProperty);
  }
 catch (  Exception e) {
    ExceptionHandler.process(e);
  }
  return object;
}