nus-yam/ex-repair huggingface dataset:
Program: 61898
Project: 61898
Buggy source:
@PATCH @Timed @ExceptionMetered @PerChannelTimed(operationName="String_Node_Str",channelNameParameter="String_Node_Str") @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) public Response updateMetadata(@PathParam("String_Node_Str") String channelName,String json) throws Exception {
  if (noSuchChannel(channelName)) {
    throw new WebApplicationException(Response.Status.NOT_FOUND);
  }
  ChannelConfiguration oldConfig=channelService.getChannelConfiguration(channelName);
  ChannelConfiguration newConfig=ChannelConfiguration.builder().withChannelConfiguration(oldConfig).withUpdateConfig(ChannelConfiguration.fromJson(json)).build();
  newConfig=channelService.updateChannel(newConfig);
  URI channelUri=linkBuilder.buildChannelUri(newConfig,uriInfo);
  Linked<ChannelConfiguration> linked=linkBuilder.buildChannelLinks(newConfig,channelUri);
  return Response.ok(channelUri).entity(linked).build();
}

Fixed version (ground truth):
@PATCH @Timed @ExceptionMetered @PerChannelTimed(operationName="String_Node_Str",channelNameParameter="String_Node_Str") @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) public Response updateMetadata(@PathParam("String_Node_Str") String channelName,String json) throws Exception {
  if (noSuchChannel(channelName)) {
    throw new WebApplicationException(Response.Status.NOT_FOUND);
  }
  ChannelConfiguration oldConfig=channelService.getChannelConfiguration(channelName);
  ChannelConfiguration.Builder builder=ChannelConfiguration.builder().withChannelConfiguration(oldConfig);
  JsonNode rootNode=mapper.readTree(json);
  if (rootNode.has("String_Node_Str")) {
    builder.withDescription(rootNode.get("String_Node_Str").asText());
  }
  if (rootNode.has("String_Node_Str")) {
    builder.withTtlDays(rootNode.get("String_Node_Str").asLong());
  }
 else   if (rootNode.has("String_Node_Str")) {
    builder.withTtlMillis(rootNode.get("String_Node_Str").asLong());
  }
  if (rootNode.has("String_Node_Str")) {
    builder.withContentKiloBytes(rootNode.get("String_Node_Str").asInt());
  }
  if (rootNode.has("String_Node_Str")) {
    builder.withPeakRequestRate(rootNode.get("String_Node_Str").asInt());
  }
  if (rootNode.has("String_Node_Str")) {
    Set<String> tags=new HashSet<>();
    JsonNode tagsNode=rootNode.get("String_Node_Str");
    for (    JsonNode tagNode : tagsNode) {
      tags.add(tagNode.asText());
    }
    builder.withTags(tags);
  }
  ChannelConfiguration newConfig=builder.build();
  newConfig=channelService.updateChannel(newConfig);
  URI channelUri=linkBuilder.buildChannelUri(newConfig,uriInfo);
  Linked<ChannelConfiguration> linked=linkBuilder.buildChannelLinks(newConfig,channelUri);
  return Response.ok(channelUri).entity(linked).build();
}
Program: 61899
Project: 61899
Buggy source:
public Builder withTags(Collection<String> tags){
  this.tags.addAll(tags);
  return this;
}

Fixed version (ground truth):
public Builder withTags(Collection<String> tags){
  this.tags.clear();
  this.tags.addAll(tags);
  return this;
}
Program: 61900
Project: 61900
Buggy source:
@PATCH @Timed @ExceptionMetered @PerChannelTimed(operationName="String_Node_Str",channelNameParameter="String_Node_Str") @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) public Response updateMetadata(@PathParam("String_Node_Str") String channelName,String json) throws Exception {
  if (noSuchChannel(channelName)) {
    throw new WebApplicationException(Response.Status.NOT_FOUND);
  }
  ChannelConfiguration oldConfig=channelService.getChannelConfiguration(channelName);
  ChannelConfiguration newConfig=ChannelConfiguration.builder().withChannelConfiguration(oldConfig).withUpdateConfig(ChannelConfiguration.fromJson(json)).build();
  newConfig=channelService.updateChannel(newConfig);
  URI channelUri=linkBuilder.buildChannelUri(newConfig,uriInfo);
  Linked<ChannelConfiguration> linked=linkBuilder.buildChannelLinks(newConfig,channelUri);
  return Response.ok(channelUri).entity(linked).build();
}

Fixed version (ground truth):
@PATCH @Timed @ExceptionMetered @PerChannelTimed(operationName="String_Node_Str",channelNameParameter="String_Node_Str") @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) public Response updateMetadata(@PathParam("String_Node_Str") String channelName,String json) throws Exception {
  if (noSuchChannel(channelName)) {
    throw new WebApplicationException(Response.Status.NOT_FOUND);
  }
  ChannelConfiguration oldConfig=channelService.getChannelConfiguration(channelName);
  ChannelConfiguration.Builder builder=ChannelConfiguration.builder().withChannelConfiguration(oldConfig);
  JsonNode rootNode=mapper.readTree(json);
  if (rootNode.has("String_Node_Str")) {
    builder.withDescription(rootNode.get("String_Node_Str").asText());
  }
  if (rootNode.has("String_Node_Str")) {
    builder.withTtlDays(rootNode.get("String_Node_Str").asLong());
  }
 else   if (rootNode.has("String_Node_Str")) {
    builder.withTtlMillis(rootNode.get("String_Node_Str").asLong());
  }
  if (rootNode.has("String_Node_Str")) {
    builder.withContentKiloBytes(rootNode.get("String_Node_Str").asInt());
  }
  if (rootNode.has("String_Node_Str")) {
    builder.withPeakRequestRate(rootNode.get("String_Node_Str").asInt());
  }
  if (rootNode.has("String_Node_Str")) {
    Set<String> tags=new HashSet<>();
    JsonNode tagsNode=rootNode.get("String_Node_Str");
    for (    JsonNode tagNode : tagsNode) {
      tags.add(tagNode.asText());
    }
    builder.withTags(tags);
  }
  ChannelConfiguration newConfig=builder.build();
  newConfig=channelService.updateChannel(newConfig);
  URI channelUri=linkBuilder.buildChannelUri(newConfig,uriInfo);
  Linked<ChannelConfiguration> linked=linkBuilder.buildChannelLinks(newConfig,channelUri);
  return Response.ok(channelUri).entity(linked).build();
}
Program: 61901
Project: 61901
Buggy source:
@Override public InsertedContentKey insert(String channelName,Content content){
  if (!content.getContentKey().isPresent()) {
    Collection<ReplicationDomain> domains=replicationDao.getDomains(false);
    for (    ReplicationDomain domain : domains) {
      if (domain.getExcludeExcept().contains(channelName)) {
        throw new ReplicatingChannelException(channelName + "String_Node_Str");
      }
    }
  }
  ChannelConfiguration configuration=channelConfigurationDao.getChannelConfiguration(channelName);
  return getContentService(channelName).insert(configuration,content);
}

Fixed version (ground truth):
@Override public InsertedContentKey insert(String channelName,Content content){
  if (!content.getContentKey().isPresent()) {
    replicationValidator.checkIfReplicating(channelName);
  }
  ChannelConfiguration configuration=channelConfigurationDao.getChannelConfiguration(channelName);
  return getContentService(channelName).insert(configuration,content);
}
Program: 61902
Project: 61902
Buggy source:
@Inject public ChannelServiceImpl(ContentServiceFinder contentServiceFinder,ChannelConfigurationDao channelConfigurationDao,CreateChannelValidator createChannelValidator,TimeIndexProcessor timeIndexProcessor,ChannelReplicator channelReplicator,ReplicationDao replicationDao){
  this.contentServiceFinder=contentServiceFinder;
  this.channelConfigurationDao=channelConfigurationDao;
  this.createChannelValidator=createChannelValidator;
  this.timeIndexProcessor=timeIndexProcessor;
  this.channelReplicator=channelReplicator;
  this.replicationDao=replicationDao;
}

Fixed version (ground truth):
@Inject public ChannelServiceImpl(ContentServiceFinder contentServiceFinder,ChannelConfigurationDao channelConfigurationDao,CreateChannelValidator createChannelValidator,TimeIndexProcessor timeIndexProcessor,ChannelReplicator channelReplicator,ReplicationValidator replicationValidator){
  this.contentServiceFinder=contentServiceFinder;
  this.channelConfigurationDao=channelConfigurationDao;
  this.createChannelValidator=createChannelValidator;
  this.timeIndexProcessor=timeIndexProcessor;
  this.channelReplicator=channelReplicator;
  this.replicationValidator=replicationValidator;
}
Program: 61903
Project: 61903
Buggy source:
public ChannelConfiguration(Builder builder){
  this.name=builder.name;
  this.creationDate=builder.creationDate;
  this.type=builder.type;
  this.contentSizeKB=builder.contentSizeKB;
  this.peakRequestRateSeconds=builder.peakRequestRateSeconds;
  this.ttlDays=builder.ttlDays;
  if (builder.ttlMillis == null) {
    this.ttlMillis=TimeUnit.DAYS.toMillis(ttlDays);
  }
 else {
    this.ttlMillis=builder.ttlMillis;
  }
  this.description=builder.description;
}

Fixed version (ground truth):
public ChannelConfiguration(Builder builder){
  this.name=builder.name;
  this.creationDate=builder.creationDate;
  this.type=builder.type;
  this.contentSizeKB=builder.contentSizeKB;
  this.peakRequestRateSeconds=builder.peakRequestRateSeconds;
  this.ttlDays=builder.ttlDays;
  if (builder.ttlMillis == null) {
    this.ttlMillis=TimeUnit.DAYS.toMillis(ttlDays);
  }
 else {
    this.ttlMillis=builder.ttlMillis;
  }
  if (builder.description == null) {
    this.description="String_Node_Str";
  }
 else {
    this.description=builder.description;
  }
}
Program: 61904
Project: 61904
Buggy source:
void create(String domain,ReplicationDomain config);

Fixed version (ground truth):
void create(ReplicationDomain domain);
Program: 61905
Project: 61905
Buggy source:
@Override public void create(final String domain,final ReplicationDomain config){
  if (!config.isValid()) {
    throw new InvalidRequestException("String_Node_Str");
  }
  curatorLock.runWithLock(new Lockable(){
    @Override public void runWithLock() throws Exception {
      config.setDomain(domain);
      replicationDao.upsert(config);
    }
  }
,LOCK_PATH,1,TimeUnit.MINUTES);
  notifyWatchers();
}

Fixed version (ground truth):
@Override public void create(final ReplicationDomain domain){
  replicationValidator.validateDomain(domain);
  curatorLock.runWithLock(new Lockable(){
    @Override public void runWithLock() throws Exception {
      replicationDao.upsert(domain);
    }
  }
,LOCK_PATH,1,TimeUnit.MINUTES);
  notifyWatchers();
}
Program: 61906
Project: 61906
Buggy source:
@Inject public ReplicationServiceImpl(ReplicationDao replicationDao,ChannelService channelService,ChannelUtils channelUtils,CuratorLock curatorLock,CuratorFramework curator,Replicator replicator){
  this.replicationDao=replicationDao;
  this.channelService=channelService;
  this.channelUtils=channelUtils;
  this.curatorLock=curatorLock;
  this.curator=curator;
  this.replicator=replicator;
}

Fixed version (ground truth):
@Inject public ReplicationServiceImpl(ReplicationDao replicationDao,ChannelService channelService,ChannelUtils channelUtils,CuratorLock curatorLock,CuratorFramework curator,Replicator replicator,ReplicationValidator replicationValidator){
  this.replicationDao=replicationDao;
  this.channelService=channelService;
  this.channelUtils=channelUtils;
  this.curatorLock=curatorLock;
  this.curator=curator;
  this.replicator=replicator;
  this.replicationValidator=replicationValidator;
}
Program: 61907
Project: 61907
Buggy source:
@PUT @Path("String_Node_Str") @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) public Response putDomain(@PathParam("String_Node_Str") String domain,ReplicationDomain replicationDomain,@HeaderParam("String_Node_Str") String host){
  logger.info("String_Node_Str" + domain + "String_Node_Str"+ replicationDomain+ "String_Node_Str"+ host);
  if (domain.equalsIgnoreCase(host)) {
    return Response.status(Response.Status.BAD_REQUEST).entity("String_Node_Str").build();
  }
  replicationService.create(domain,replicationDomain);
  return Response.created(uriInfo.getRequestUri()).entity(replicationDomain).build();
}

Fixed version (ground truth):
@PUT @Path("String_Node_Str") @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) public Response putDomain(@PathParam("String_Node_Str") String domain,ReplicationDomain replicationDomain,@HeaderParam("String_Node_Str") String host){
  logger.info("String_Node_Str" + domain + "String_Node_Str"+ replicationDomain+ "String_Node_Str"+ host);
  if (domain.equalsIgnoreCase(host)) {
    return Response.status(Response.Status.BAD_REQUEST).entity("String_Node_Str").build();
  }
  replicationDomain.setDomain(domain);
  replicationService.create(replicationDomain);
  return Response.created(uriInfo.getRequestUri()).entity(replicationDomain).build();
}
Program: 61908
Project: 61908
Buggy source:
@Override public InsertedContentKey insert(String channelName,Content content){
  if (!content.getContentKey().isPresent()) {
    Collection<ReplicationDomain> domains=replicationDao.getDomains(false);
    for (    ReplicationDomain domain : domains) {
      if (domain.getExcludeExcept().contains(channelName)) {
        throw new ReplicatingChannelException(channelName + "String_Node_Str");
      }
    }
  }
  ChannelConfiguration configuration=channelConfigurationDao.getChannelConfiguration(channelName);
  return getContentService(channelName).insert(configuration,content);
}

Fixed version (ground truth):
@Override public InsertedContentKey insert(String channelName,Content content){
  if (!content.getContentKey().isPresent()) {
    replicationValidator.checkIfReplicating(channelName);
  }
  ChannelConfiguration configuration=channelConfigurationDao.getChannelConfiguration(channelName);
  return getContentService(channelName).insert(configuration,content);
}
Program: 61909
Project: 61909
Buggy source:
@Inject public ChannelServiceImpl(ContentServiceFinder contentServiceFinder,ChannelConfigurationDao channelConfigurationDao,CreateChannelValidator createChannelValidator,TimeIndexProcessor timeIndexProcessor,ChannelReplicator channelReplicator,ReplicationDao replicationDao){
  this.contentServiceFinder=contentServiceFinder;
  this.channelConfigurationDao=channelConfigurationDao;
  this.createChannelValidator=createChannelValidator;
  this.timeIndexProcessor=timeIndexProcessor;
  this.channelReplicator=channelReplicator;
  this.replicationDao=replicationDao;
}

Fixed version (ground truth):
@Inject public ChannelServiceImpl(ContentServiceFinder contentServiceFinder,ChannelConfigurationDao channelConfigurationDao,CreateChannelValidator createChannelValidator,TimeIndexProcessor timeIndexProcessor,ChannelReplicator channelReplicator,ReplicationValidator replicationValidator){
  this.contentServiceFinder=contentServiceFinder;
  this.channelConfigurationDao=channelConfigurationDao;
  this.createChannelValidator=createChannelValidator;
  this.timeIndexProcessor=timeIndexProcessor;
  this.channelReplicator=channelReplicator;
  this.replicationValidator=replicationValidator;
}
Program: 61910
Project: 61910
Buggy source:
public ChannelConfiguration(Builder builder){
  this.name=builder.name;
  this.creationDate=builder.creationDate;
  this.type=builder.type;
  this.contentSizeKB=builder.contentSizeKB;
  this.peakRequestRateSeconds=builder.peakRequestRateSeconds;
  this.ttlDays=builder.ttlDays;
  if (builder.ttlMillis == null) {
    this.ttlMillis=TimeUnit.DAYS.toMillis(ttlDays);
  }
 else {
    this.ttlMillis=builder.ttlMillis;
  }
  this.description=builder.description;
}

Fixed version (ground truth):
public ChannelConfiguration(Builder builder){
  this.name=builder.name;
  this.creationDate=builder.creationDate;
  this.type=builder.type;
  this.contentSizeKB=builder.contentSizeKB;
  this.peakRequestRateSeconds=builder.peakRequestRateSeconds;
  this.ttlDays=builder.ttlDays;
  if (builder.ttlMillis == null) {
    this.ttlMillis=TimeUnit.DAYS.toMillis(ttlDays);
  }
 else {
    this.ttlMillis=builder.ttlMillis;
  }
  if (builder.description == null) {
    this.description="String_Node_Str";
  }
 else {
    this.description=builder.description;
  }
}
Program: 61911
Project: 61911
Buggy source:
void create(String domain,ReplicationDomain config);

Fixed version (ground truth):
void create(ReplicationDomain domain);
Program: 61912
Project: 61912
Buggy source:
@Override public void create(final String domain,final ReplicationDomain config){
  if (!config.isValid()) {
    throw new InvalidRequestException("String_Node_Str");
  }
  curatorLock.runWithLock(new Lockable(){
    @Override public void runWithLock() throws Exception {
      config.setDomain(domain);
      replicationDao.upsert(config);
    }
  }
,LOCK_PATH,1,TimeUnit.MINUTES);
  notifyWatchers();
}

Fixed version (ground truth):
@Override public void create(final ReplicationDomain domain){
  replicationValidator.validateDomain(domain);
  curatorLock.runWithLock(new Lockable(){
    @Override public void runWithLock() throws Exception {
      replicationDao.upsert(domain);
    }
  }
,LOCK_PATH,1,TimeUnit.MINUTES);
  notifyWatchers();
}
Program: 61913
Project: 61913
Buggy source:
@Inject public ReplicationServiceImpl(ReplicationDao replicationDao,ChannelService channelService,ChannelUtils channelUtils,CuratorLock curatorLock,CuratorFramework curator,Replicator replicator){
  this.replicationDao=replicationDao;
  this.channelService=channelService;
  this.channelUtils=channelUtils;
  this.curatorLock=curatorLock;
  this.curator=curator;
  this.replicator=replicator;
}

Fixed version (ground truth):
@Inject public ReplicationServiceImpl(ReplicationDao replicationDao,ChannelService channelService,ChannelUtils channelUtils,CuratorLock curatorLock,CuratorFramework curator,Replicator replicator,ReplicationValidator replicationValidator){
  this.replicationDao=replicationDao;
  this.channelService=channelService;
  this.channelUtils=channelUtils;
  this.curatorLock=curatorLock;
  this.curator=curator;
  this.replicator=replicator;
  this.replicationValidator=replicationValidator;
}
Program: 61914
Project: 61914
Buggy source:
@PUT @Path("String_Node_Str") @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) public Response putDomain(@PathParam("String_Node_Str") String domain,ReplicationDomain replicationDomain,@HeaderParam("String_Node_Str") String host){
  logger.info("String_Node_Str" + domain + "String_Node_Str"+ replicationDomain+ "String_Node_Str"+ host);
  if (domain.equalsIgnoreCase(host)) {
    return Response.status(Response.Status.BAD_REQUEST).entity("String_Node_Str").build();
  }
  replicationService.create(domain,replicationDomain);
  return Response.created(uriInfo.getRequestUri()).entity(replicationDomain).build();
}

Fixed version (ground truth):
@PUT @Path("String_Node_Str") @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) public Response putDomain(@PathParam("String_Node_Str") String domain,ReplicationDomain replicationDomain,@HeaderParam("String_Node_Str") String host){
  logger.info("String_Node_Str" + domain + "String_Node_Str"+ replicationDomain+ "String_Node_Str"+ host);
  if (domain.equalsIgnoreCase(host)) {
    return Response.status(Response.Status.BAD_REQUEST).entity("String_Node_Str").build();
  }
  replicationDomain.setDomain(domain);
  replicationService.create(replicationDomain);
  return Response.created(uriInfo.getRequestUri()).entity(replicationDomain).build();
}
Program: 61915
Project: 61915
Buggy source:
@Override public InsertedContentKey write(String channelName,Content content,long ttlDays){
  if (!content.getContentKey().isPresent()) {
    content.setContentKey(keyGenerator.newKey(channelName));
  }
  ContentKey key=content.getContentKey().get();
  DateTime dateTime=new DateTime(content.getMillis());
  writeS3(channelName,content,key);
  writeIndex(channelName,dateTime,key);
  return new InsertedContentKey(key,dateTime.toDate());
}

Fixed version (ground truth):
@Override public InsertedContentKey write(String channelName,Content content,long ttlDays){
  if (content.getContentKey().isPresent()) {
    keyGenerator.setLatest(channelName,content.getContentKey().get());
  }
 else {
    content.setContentKey(keyGenerator.newKey(channelName));
  }
  ContentKey key=content.getContentKey().get();
  DateTime dateTime=new DateTime(content.getMillis());
  writeS3(channelName,content,key);
  writeIndex(channelName,dateTime,key);
  return new InsertedContentKey(key,dateTime.toDate());
}
Program: 61916
Project: 61916
Buggy source:
@Override public InsertedContentKey insert(String channelName,Content content){
  if (!content.getContentKey().isPresent()) {
    Collection<ReplicationDomain> domains=replicationDao.getDomains(false);
    for (    ReplicationDomain domain : domains) {
      if (domain.getExcludeExcept().contains(channelName)) {
        throw new ReplicatingChannelException(channelName + "String_Node_Str");
      }
    }
  }
  ChannelConfiguration configuration=channelConfigurationDao.getChannelConfiguration(channelName);
  return getContentService(channelName).insert(configuration,content);
}

Fixed version (ground truth):
@Override public InsertedContentKey insert(String channelName,Content content){
  if (!content.getContentKey().isPresent()) {
    replicationValidator.checkIfReplicating(channelName);
  }
  ChannelConfiguration configuration=channelConfigurationDao.getChannelConfiguration(channelName);
  return getContentService(channelName).insert(configuration,content);
}
Program: 61917
Project: 61917
Buggy source:
@Inject public ChannelServiceImpl(ContentServiceFinder contentServiceFinder,ChannelConfigurationDao channelConfigurationDao,CreateChannelValidator createChannelValidator,TimeIndexProcessor timeIndexProcessor,ChannelReplicator channelReplicator,ReplicationDao replicationDao){
  this.contentServiceFinder=contentServiceFinder;
  this.channelConfigurationDao=channelConfigurationDao;
  this.createChannelValidator=createChannelValidator;
  this.timeIndexProcessor=timeIndexProcessor;
  this.channelReplicator=channelReplicator;
  this.replicationDao=replicationDao;
}

Fixed version (ground truth):
@Inject public ChannelServiceImpl(ContentServiceFinder contentServiceFinder,ChannelConfigurationDao channelConfigurationDao,CreateChannelValidator createChannelValidator,TimeIndexProcessor timeIndexProcessor,ChannelReplicator channelReplicator,ReplicationValidator replicationValidator){
  this.contentServiceFinder=contentServiceFinder;
  this.channelConfigurationDao=channelConfigurationDao;
  this.createChannelValidator=createChannelValidator;
  this.timeIndexProcessor=timeIndexProcessor;
  this.channelReplicator=channelReplicator;
  this.replicationValidator=replicationValidator;
}
Program: 61918
Project: 61918
Buggy source:
public ChannelConfiguration(Builder builder){
  this.name=builder.name;
  this.creationDate=builder.creationDate;
  this.type=builder.type;
  this.contentSizeKB=builder.contentSizeKB;
  this.peakRequestRateSeconds=builder.peakRequestRateSeconds;
  this.ttlDays=builder.ttlDays;
  if (builder.ttlMillis == null) {
    this.ttlMillis=TimeUnit.DAYS.toMillis(ttlDays);
  }
 else {
    this.ttlMillis=builder.ttlMillis;
  }
  this.description=builder.description;
}

Fixed version (ground truth):
public ChannelConfiguration(Builder builder){
  this.name=builder.name;
  this.creationDate=builder.creationDate;
  this.type=builder.type;
  this.contentSizeKB=builder.contentSizeKB;
  this.peakRequestRateSeconds=builder.peakRequestRateSeconds;
  this.ttlDays=builder.ttlDays;
  if (builder.ttlMillis == null) {
    this.ttlMillis=TimeUnit.DAYS.toMillis(ttlDays);
  }
 else {
    this.ttlMillis=builder.ttlMillis;
  }
  if (builder.description == null) {
    this.description="String_Node_Str";
  }
 else {
    this.description=builder.description;
  }
}
Program: 61919
Project: 61919
Buggy source:
void create(String domain,ReplicationDomain config);

Fixed version (ground truth):
void create(ReplicationDomain domain);
Program: 61920
Project: 61920
Buggy source:
@Override public void create(final String domain,final ReplicationDomain config){
  if (!config.isValid()) {
    throw new InvalidRequestException("String_Node_Str");
  }
  curatorLock.runWithLock(new Lockable(){
    @Override public void runWithLock() throws Exception {
      config.setDomain(domain);
      replicationDao.upsert(config);
    }
  }
,LOCK_PATH,1,TimeUnit.MINUTES);
  notifyWatchers();
}

Fixed version (ground truth):
@Override public void create(final ReplicationDomain domain){
  replicationValidator.validateDomain(domain);
  curatorLock.runWithLock(new Lockable(){
    @Override public void runWithLock() throws Exception {
      replicationDao.upsert(domain);
    }
  }
,LOCK_PATH,1,TimeUnit.MINUTES);
  notifyWatchers();
}
Program: 61921
Project: 61921
Buggy source:
@Inject public ReplicationServiceImpl(ReplicationDao replicationDao,ChannelService channelService,ChannelUtils channelUtils,CuratorLock curatorLock,CuratorFramework curator,Replicator replicator){
  this.replicationDao=replicationDao;
  this.channelService=channelService;
  this.channelUtils=channelUtils;
  this.curatorLock=curatorLock;
  this.curator=curator;
  this.replicator=replicator;
}

Fixed version (ground truth):
@Inject public ReplicationServiceImpl(ReplicationDao replicationDao,ChannelService channelService,ChannelUtils channelUtils,CuratorLock curatorLock,CuratorFramework curator,Replicator replicator,ReplicationValidator replicationValidator){
  this.replicationDao=replicationDao;
  this.channelService=channelService;
  this.channelUtils=channelUtils;
  this.curatorLock=curatorLock;
  this.curator=curator;
  this.replicator=replicator;
  this.replicationValidator=replicationValidator;
}
Program: 61922
Project: 61922
Buggy source:
@PUT @Path("String_Node_Str") @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) public Response putDomain(@PathParam("String_Node_Str") String domain,ReplicationDomain replicationDomain,@HeaderParam("String_Node_Str") String host){
  logger.info("String_Node_Str" + domain + "String_Node_Str"+ replicationDomain+ "String_Node_Str"+ host);
  if (domain.equalsIgnoreCase(host)) {
    return Response.status(Response.Status.BAD_REQUEST).entity("String_Node_Str").build();
  }
  replicationService.create(domain,replicationDomain);
  return Response.created(uriInfo.getRequestUri()).entity(replicationDomain).build();
}

Fixed version (ground truth):
@PUT @Path("String_Node_Str") @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) public Response putDomain(@PathParam("String_Node_Str") String domain,ReplicationDomain replicationDomain,@HeaderParam("String_Node_Str") String host){
  logger.info("String_Node_Str" + domain + "String_Node_Str"+ replicationDomain+ "String_Node_Str"+ host);
  if (domain.equalsIgnoreCase(host)) {
    return Response.status(Response.Status.BAD_REQUEST).entity("String_Node_Str").build();
  }
  replicationDomain.setDomain(domain);
  replicationService.create(replicationDomain);
  return Response.created(uriInfo.getRequestUri()).entity(replicationDomain).build();
}
Program: 61923
Project: 61923
Buggy source:
@Override public InsertedContentKey write(String channelName,Content content,long ttlDays){
  if (!content.getContentKey().isPresent()) {
    content.setContentKey(keyGenerator.newKey(channelName));
  }
  ContentKey key=content.getContentKey().get();
  DateTime dateTime=new DateTime(content.getMillis());
  writeS3(channelName,content,key);
  writeIndex(channelName,dateTime,key);
  return new InsertedContentKey(key,dateTime.toDate());
}

Fixed version (ground truth):
@Override public InsertedContentKey write(String channelName,Content content,long ttlDays){
  if (content.getContentKey().isPresent()) {
    keyGenerator.setLatest(channelName,content.getContentKey().get());
  }
 else {
    content.setContentKey(keyGenerator.newKey(channelName));
  }
  ContentKey key=content.getContentKey().get();
  DateTime dateTime=new DateTime(content.getMillis());
  writeS3(channelName,content,key);
  writeIndex(channelName,dateTime,key);
  return new InsertedContentKey(key,dateTime.toDate());
}
Program: 61924
Project: 61924
Buggy source:
@Override public InsertedContentKey write(String channelName,Content content,long ttlDays){
  if (!content.getContentKey().isPresent()) {
    content.setContentKey(keyGenerator.newKey(channelName));
  }
  ContentKey key=content.getContentKey().get();
  DateTime dateTime=new DateTime(content.getMillis());
  writeS3(channelName,content,key);
  writeIndex(channelName,dateTime,key);
  return new InsertedContentKey(key,dateTime.toDate());
}

Fixed version (ground truth):
@Override public InsertedContentKey write(String channelName,Content content,long ttlDays){
  if (content.getContentKey().isPresent()) {
    keyGenerator.setLatest(channelName,content.getContentKey().get());
  }
 else {
    content.setContentKey(keyGenerator.newKey(channelName));
  }
  ContentKey key=content.getContentKey().get();
  DateTime dateTime=new DateTime(content.getMillis());
  writeS3(channelName,content,key);
  writeIndex(channelName,dateTime,key);
  return new InsertedContentKey(key,dateTime.toDate());
}
Program: 61925
Project: 61925
Buggy source:
private void replicate(){
  long sequence=getStartingSequence();
  if (sequence == ChannelUtils.NOT_FOUND) {
    return;
  }
  logger.info("String_Node_Str" + channel.getUrl() + "String_Node_Str"+ sequence);
  iterator=sequenceIteratorFactory.create(sequence,channel);
  while (iterator.hasNext() && curatorLock.shouldKeepWorking()) {
    channelService.insert(channel.getName(),iterator.next());
  }
}

Fixed version (ground truth):
private void replicate(){
  long sequence=getStartingSequence();
  if (sequence == ChannelUtils.NOT_FOUND) {
    return;
  }
  logger.info("String_Node_Str" + channel.getUrl() + "String_Node_Str"+ sequence);
  iterator=sequenceIteratorFactory.create(sequence,channel);
  while (iterator.hasNext() && curatorLock.shouldKeepWorking()) {
    Optional<Content> optionalContent=iterator.next();
    if (optionalContent.isPresent()) {
      channelService.insert(channel.getName(),optionalContent.get());
    }
  }
}
Program: 61926
Project: 61926
Buggy source:
public Optional<Long> getLatestSequence(String channelUrl){
  channelUrl=appendSlash(channelUrl);
  ClientResponse response=noRedirectsClient.resource(channelUrl + "String_Node_Str").accept(MediaType.WILDCARD_TYPE).head();
  if (response.getStatus() != Response.Status.SEE_OTHER.getStatusCode()) {
    logger.debug("String_Node_Str" + channelUrl + "String_Node_Str"+ response);
    return Optional.absent();
  }
  String location=response.getLocation().toString();
  String substring=location.substring(channelUrl.length());
  return Optional.of(Long.parseLong(substring));
}

Fixed version (ground truth):
public Optional<Long> getLatestSequence(String channelUrl){
  channelUrl=appendSlash(channelUrl);
  ClientResponse response=noRedirectsClient.resource(channelUrl + "String_Node_Str").accept(MediaType.WILDCARD_TYPE).head();
  if (response.getStatus() != Response.Status.SEE_OTHER.getStatusCode()) {
    logger.info("String_Node_Str" + channelUrl + "String_Node_Str"+ response);
    return Optional.absent();
  }
  String location=response.getLocation().toString();
  String substring=location.substring(channelUrl.length());
  return Optional.of(Long.parseLong(substring));
}
Program: 61927
Project: 61927
Buggy source:
@Override public Content next(){
  Optional<Content> optional=channelUtils.getContent(channelUrl,current);
  while (!optional.isPresent()) {
    logger.warn("String_Node_Str" + channelUrl + "String_Node_Str"+ current);
    current++;
    optional=channelUtils.getContent(channelUrl,current);
  }
  return optional.get();
}

Fixed version (ground truth):
@Override public Optional<Content> next(){
  Optional<Content> optional=channelUtils.getContent(channelUrl,current);
  if (!optional.isPresent()) {
    logger.warn("String_Node_Str" + channelUrl + "String_Node_Str"+ current);
    optional=channelUtils.getContent(channelUrl,current);
  }
  return optional;
}
Program: 61928
Project: 61928
Buggy source:
@OnError public void onError(Throwable throwable){
  if (throwable.getClass().isAssignableFrom(SocketTimeoutException.class) || throwable.getClass().isAssignableFrom(EOFException.class)) {
    logger.info("String_Node_Str" + channelUrl + "String_Node_Str"+ throwable.getMessage());
  }
 else {
    logger.warn("String_Node_Str" + channelUrl,throwable);
  }
  exit();
}

Fixed version (ground truth):
@OnError public void onError(Throwable throwable){
  if (throwable.getClass().isAssignableFrom(SocketTimeoutException.class) || throwable.getClass().isAssignableFrom(EOFException.class)) {
    logger.info("String_Node_Str" + channel + "String_Node_Str"+ throwable.getMessage());
  }
 else {
    logger.warn("String_Node_Str" + channel,throwable);
  }
  exit();
}
Program: 61929
Project: 61929
Buggy source:
@OnClose public void onClose(CloseReason reason){
  logger.info("String_Node_Str" + reason);
  exit();
}

Fixed version (ground truth):
@OnClose public void onClose(CloseReason reason){
  logger.info("String_Node_Str" + reason + "String_Node_Str"+ channel);
  exit();
}
Program: 61930
Project: 61930
Buggy source:
@OnMessage public void onMessage(String message){
  try {
    long sequence=Long.parseLong(StringUtils.substringAfterLast(message,"String_Node_Str"));
    logger.debug("String_Node_Str",sequence);
    if (sequence > latest.get()) {
      latest.set(sequence);
    }
    signal();
  }
 catch (  Exception e) {
    logger.warn("String_Node_Str" + message + "String_Node_Str"+ channelUrl,e);
  }
}

Fixed version (ground truth):
@OnMessage public void onMessage(String message){
  try {
    long sequence=Long.parseLong(StringUtils.substringAfterLast(message,"String_Node_Str"));
    logger.debug("String_Node_Str",channel,sequence);
    if (sequence > latest.get()) {
      latest.set(sequence);
      signal();
    }
  }
 catch (  Exception e) {
    logger.warn("String_Node_Str" + message + "String_Node_Str"+ channel,e);
  }
}
Program: 61931
Project: 61931
Buggy source:
public ClientResponse handle(ClientRequest clientRequest) throws ClientHandlerException {
  int i=0;
  int maxRetries=3;
  int sleep=1000;
  ClientHandlerException lastCause=null;
  while (i < maxRetries) {
    i++;
    try {
      ClientResponse response=getNext().handle(clientRequest);
      if (response.getStatus() >= 500) {
        logger.info("String_Node_Str",response,i);
        if (i >= maxRetries) {
          return response;
        }
      }
 else {
        return response;
      }
    }
 catch (    ClientHandlerException e) {
      if (e.getCause() == null) {
        throw e;
      }
      if (UnknownHostException.class.isAssignableFrom(e.getCause().getClass())) {
        throw e;
      }
      lastCause=e;
      logger.info("String_Node_Str",clientRequest.getURI().toString(),i);
      logger.debug(clientRequest.getURI().toString() + "String_Node_Str",e);
      Sleeper.sleep(sleep * i);
    }
  }
  String msg="String_Node_Str" + maxRetries + "String_Node_Str"+ clientRequest.getURI();
  logger.warn(msg);
  throw lastCause;
}

Fixed version (ground truth):
public ClientResponse handle(ClientRequest clientRequest) throws ClientHandlerException {
  int maxRetries=5;
  int sleep=1000;
  ClientHandlerException lastCause=null;
  int attempt=0;
  while (attempt < maxRetries) {
    attempt++;
    try {
      ClientResponse response=getNext().handle(clientRequest);
      if (response.getStatus() >= 500) {
        logger.info("String_Node_Str",response,attempt);
        if (attempt >= maxRetries) {
          return response;
        }
      }
 else {
        return response;
      }
    }
 catch (    ClientHandlerException e) {
      if (e.getCause() == null) {
        throw e;
      }
      if (UnknownHostException.class.isAssignableFrom(e.getCause().getClass())) {
        throw e;
      }
      lastCause=e;
      logger.info("String_Node_Str",clientRequest.getURI().toString(),attempt);
      logger.debug(clientRequest.getURI().toString() + "String_Node_Str",e);
      Sleeper.sleep(sleep * 2 ^ attempt);
    }
  }
  String msg="String_Node_Str" + maxRetries + "String_Node_Str"+ clientRequest.getURI();
  logger.warn(msg);
  throw lastCause;
}
Program: 61932
Project: 61932
Buggy source:
@Test public void testLifeCycleNew() throws Exception {
  Content content=mock(Content.class);
  when(sequenceIterator.hasNext()).thenReturn(true).thenReturn(true).thenReturn(false);
  when(sequenceIterator.next()).thenReturn(content).thenReturn(content).thenReturn(null);
  when(channelUtils.getLatestSequence(URL)).thenReturn(Optional.<Long>absent());
  replicator.verifyRemoteChannel();
  replicator.runWithLock();
  verify(channelService).createChannel(configuration);
  verify(channelService,new Times(2)).insert(CHANNEL,content);
}

Fixed version (ground truth):
@Test public void testLifeCycleNew() throws Exception {
  Content content=mock(Content.class);
  Optional<Content> optional=Optional.of(content);
  when(sequenceIterator.hasNext()).thenReturn(true).thenReturn(true).thenReturn(false);
  when(sequenceIterator.next()).thenReturn(optional).thenReturn(optional).thenReturn(null);
  when(channelUtils.getLatestSequence(URL)).thenReturn(Optional.<Long>absent());
  replicator.verifyRemoteChannel();
  replicator.runWithLock();
  verify(channelService).createChannel(configuration);
  verify(channelService,new Times(2)).insert(CHANNEL,content);
}
Program: 61933
Project: 61933
Buggy source:
public static void main(String[] args) throws Exception {
  Client noRedirects=GuiceContext.HubCommonModule.buildJerseyClientNoRedirects();
  Client follows=GuiceContext.HubCommonModule.buildJerseyClient();
  ChannelUtils channelUtils=new ChannelUtils(noRedirects,follows);
  ClientContainer container=new ClientContainer();
  container.start();
  MetricRegistry metricRegistry=new MetricRegistry();
  ConsoleReporter reporter=ConsoleReporter.forRegistry(metricRegistry).build();
  reporter.start(1,TimeUnit.SECONDS);
  Channel testy10=new Channel("String_Node_Str","String_Node_Str");
  SequenceIterator iterator=new SequenceIterator(700457,channelUtils,testy10,container,metricRegistry);
  while (iterator.hasNext()) {
    Content next=iterator.next();
  }
  logger.info("String_Node_Str");
}

Fixed version (ground truth):
public static void main(String[] args) throws Exception {
  Client noRedirects=GuiceContext.HubCommonModule.buildJerseyClientNoRedirects();
  Client follows=GuiceContext.HubCommonModule.buildJerseyClient();
  ChannelUtils channelUtils=new ChannelUtils(noRedirects,follows);
  ClientContainer container=new ClientContainer();
  container.start();
  MetricRegistry metricRegistry=new MetricRegistry();
  ConsoleReporter reporter=ConsoleReporter.forRegistry(metricRegistry).build();
  reporter.start(1,TimeUnit.SECONDS);
  Channel testy10=new Channel("String_Node_Str","String_Node_Str");
  SequenceIterator iterator=new SequenceIterator(700457,channelUtils,testy10,container,metricRegistry);
  while (iterator.hasNext()) {
  }
  logger.info("String_Node_Str");
}
Program: 61934
Project: 61934
Buggy source:
private void check(SequenceIterator iterator,String data){
  assertTrue(iterator.hasNext());
  Content content=iterator.next();
  logger.debug("String_Node_Str" + new String(content.getData()) + "String_Node_Str"+ content.getContentKey().get());
  assertNotNull(content);
  assertArrayEquals(data.getBytes(),content.getData());
}

Fixed version (ground truth):
private void check(SequenceIterator iterator,String data){
  assertTrue(iterator.hasNext());
  Content content=iterator.next().get();
  logger.debug("String_Node_Str" + new String(content.getData()) + "String_Node_Str"+ content.getContentKey().get());
  assertNotNull(content);
  assertArrayEquals(data.getBytes(),content.getData());
}
Program: 61935
Project: 61935
Buggy source:
private void replicate(){
  long sequence=getStartingSequence();
  if (sequence == ChannelUtils.NOT_FOUND) {
    return;
  }
  logger.info("String_Node_Str" + channel.getUrl() + "String_Node_Str"+ sequence);
  iterator=sequenceIteratorFactory.create(sequence,channel);
  while (iterator.hasNext() && curatorLock.shouldKeepWorking()) {
    channelService.insert(channel.getName(),iterator.next());
  }
}

Fixed version (ground truth):
private void replicate(){
  long sequence=getStartingSequence();
  if (sequence == ChannelUtils.NOT_FOUND) {
    return;
  }
  logger.info("String_Node_Str" + channel.getUrl() + "String_Node_Str"+ sequence);
  iterator=sequenceIteratorFactory.create(sequence,channel);
  while (iterator.hasNext() && curatorLock.shouldKeepWorking()) {
    Optional<Content> optionalContent=iterator.next();
    if (optionalContent.isPresent()) {
      channelService.insert(channel.getName(),optionalContent.get());
    }
  }
}
Program: 61936
Project: 61936
Buggy source:
public Optional<Long> getLatestSequence(String channelUrl){
  channelUrl=appendSlash(channelUrl);
  ClientResponse response=noRedirectsClient.resource(channelUrl + "String_Node_Str").accept(MediaType.WILDCARD_TYPE).head();
  if (response.getStatus() != Response.Status.SEE_OTHER.getStatusCode()) {
    logger.debug("String_Node_Str" + channelUrl + "String_Node_Str"+ response);
    return Optional.absent();
  }
  String location=response.getLocation().toString();
  String substring=location.substring(channelUrl.length());
  return Optional.of(Long.parseLong(substring));
}

Fixed version (ground truth):
public Optional<Long> getLatestSequence(String channelUrl){
  channelUrl=appendSlash(channelUrl);
  ClientResponse response=noRedirectsClient.resource(channelUrl + "String_Node_Str").accept(MediaType.WILDCARD_TYPE).head();
  if (response.getStatus() != Response.Status.SEE_OTHER.getStatusCode()) {
    logger.info("String_Node_Str" + channelUrl + "String_Node_Str"+ response);
    return Optional.absent();
  }
  String location=response.getLocation().toString();
  String substring=location.substring(channelUrl.length());
  return Optional.of(Long.parseLong(substring));
}
Program: 61937
Project: 61937
Buggy source:
@Override public Content next(){
  Optional<Content> optional=channelUtils.getContent(channelUrl,current);
  while (!optional.isPresent()) {
    logger.warn("String_Node_Str" + channelUrl + "String_Node_Str"+ current);
    current++;
    optional=channelUtils.getContent(channelUrl,current);
  }
  return optional.get();
}

Fixed version (ground truth):
@Override public Optional<Content> next(){
  Optional<Content> optional=channelUtils.getContent(channelUrl,current);
  if (!optional.isPresent()) {
    logger.warn("String_Node_Str" + channelUrl + "String_Node_Str"+ current);
    optional=channelUtils.getContent(channelUrl,current);
  }
  return optional;
}
Program: 61938
Project: 61938
Buggy source:
@OnError public void onError(Throwable throwable){
  if (throwable.getClass().isAssignableFrom(SocketTimeoutException.class) || throwable.getClass().isAssignableFrom(EOFException.class)) {
    logger.info("String_Node_Str" + channelUrl + "String_Node_Str"+ throwable.getMessage());
  }
 else {
    logger.warn("String_Node_Str" + channelUrl,throwable);
  }
  exit();
}

Fixed version (ground truth):
@OnError public void onError(Throwable throwable){
  if (throwable.getClass().isAssignableFrom(SocketTimeoutException.class) || throwable.getClass().isAssignableFrom(EOFException.class)) {
    logger.info("String_Node_Str" + channel + "String_Node_Str"+ throwable.getMessage());
  }
 else {
    logger.warn("String_Node_Str" + channel,throwable);
  }
  exit();
}
Program: 61939
Project: 61939
Buggy source:
@OnClose public void onClose(CloseReason reason){
  logger.info("String_Node_Str" + reason);
  exit();
}

Fixed version (ground truth):
@OnClose public void onClose(CloseReason reason){
  logger.info("String_Node_Str" + reason + "String_Node_Str"+ channel);
  exit();
}
Program: 61940
Project: 61940
Buggy source:
@OnMessage public void onMessage(String message){
  try {
    long sequence=Long.parseLong(StringUtils.substringAfterLast(message,"String_Node_Str"));
    logger.debug("String_Node_Str",sequence);
    if (sequence > latest.get()) {
      latest.set(sequence);
    }
    signal();
  }
 catch (  Exception e) {
    logger.warn("String_Node_Str" + message + "String_Node_Str"+ channelUrl,e);
  }
}

Fixed version (ground truth):
@OnMessage public void onMessage(String message){
  try {
    long sequence=Long.parseLong(StringUtils.substringAfterLast(message,"String_Node_Str"));
    logger.debug("String_Node_Str",channel,sequence);
    if (sequence > latest.get()) {
      latest.set(sequence);
      signal();
    }
  }
 catch (  Exception e) {
    logger.warn("String_Node_Str" + message + "String_Node_Str"+ channel,e);
  }
}
Program: 61941
Project: 61941
Buggy source:
public ClientResponse handle(ClientRequest clientRequest) throws ClientHandlerException {
  int i=0;
  int maxRetries=3;
  int sleep=1000;
  ClientHandlerException lastCause=null;
  while (i < maxRetries) {
    i++;
    try {
      ClientResponse response=getNext().handle(clientRequest);
      if (response.getStatus() >= 500) {
        logger.info("String_Node_Str",response,i);
        if (i >= maxRetries) {
          return response;
        }
      }
 else {
        return response;
      }
    }
 catch (    ClientHandlerException e) {
      if (e.getCause() == null) {
        throw e;
      }
      if (UnknownHostException.class.isAssignableFrom(e.getCause().getClass())) {
        throw e;
      }
      lastCause=e;
      logger.info("String_Node_Str",clientRequest.getURI().toString(),i);
      logger.debug(clientRequest.getURI().toString() + "String_Node_Str",e);
      Sleeper.sleep(sleep * i);
    }
  }
  String msg="String_Node_Str" + maxRetries + "String_Node_Str"+ clientRequest.getURI();
  logger.warn(msg);
  throw lastCause;
}

Fixed version (ground truth):
public ClientResponse handle(ClientRequest clientRequest) throws ClientHandlerException {
  int maxRetries=5;
  int sleep=1000;
  ClientHandlerException lastCause=null;
  int attempt=0;
  while (attempt < maxRetries) {
    attempt++;
    try {
      ClientResponse response=getNext().handle(clientRequest);
      if (response.getStatus() >= 500) {
        logger.info("String_Node_Str",response,attempt);
        if (attempt >= maxRetries) {
          return response;
        }
      }
 else {
        return response;
      }
    }
 catch (    ClientHandlerException e) {
      if (e.getCause() == null) {
        throw e;
      }
      if (UnknownHostException.class.isAssignableFrom(e.getCause().getClass())) {
        throw e;
      }
      lastCause=e;
      logger.info("String_Node_Str",clientRequest.getURI().toString(),attempt);
      logger.debug(clientRequest.getURI().toString() + "String_Node_Str",e);
      Sleeper.sleep(sleep * 2 ^ attempt);
    }
  }
  String msg="String_Node_Str" + maxRetries + "String_Node_Str"+ clientRequest.getURI();
  logger.warn(msg);
  throw lastCause;
}
Program: 61942
Project: 61942
Buggy source:
@Test public void testLifeCycleNew() throws Exception {
  Content content=mock(Content.class);
  when(sequenceIterator.hasNext()).thenReturn(true).thenReturn(true).thenReturn(false);
  when(sequenceIterator.next()).thenReturn(content).thenReturn(content).thenReturn(null);
  when(channelUtils.getLatestSequence(URL)).thenReturn(Optional.<Long>absent());
  replicator.verifyRemoteChannel();
  replicator.runWithLock();
  verify(channelService).createChannel(configuration);
  verify(channelService,new Times(2)).insert(CHANNEL,content);
}

Fixed version (ground truth):
@Test public void testLifeCycleNew() throws Exception {
  Content content=mock(Content.class);
  Optional<Content> optional=Optional.of(content);
  when(sequenceIterator.hasNext()).thenReturn(true).thenReturn(true).thenReturn(false);
  when(sequenceIterator.next()).thenReturn(optional).thenReturn(optional).thenReturn(null);
  when(channelUtils.getLatestSequence(URL)).thenReturn(Optional.<Long>absent());
  replicator.verifyRemoteChannel();
  replicator.runWithLock();
  verify(channelService).createChannel(configuration);
  verify(channelService,new Times(2)).insert(CHANNEL,content);
}