nus-yam/ex-repair huggingface dataset:
Program: 167237
Project: 167237
Buggy source:
/** 
 * Close the file handle and rename the temp file to the permanent filename. Safe to call multiple times. Logs HDFSWriter.close() exceptions.
 * @throws IOException On failure to rename if temp file exists.
 * @throws InterruptedException
 */
public synchronized void close() throws IOException, InterruptedException {
  checkAndThrowInterruptedException();
  flush();
  LOG.debug("String_Node_Str",bucketPath);
  if (isOpen) {
    try {
      callWithTimeout(new CallRunner<Void>(){
        @Override public Void call() throws Exception {
          writer.close();
          return null;
        }
      }
);
      sinkCounter.incrementConnectionClosedCount();
    }
 catch (    IOException e) {
      LOG.warn("String_Node_Str" + bucketPath + "String_Node_Str",e);
      sinkCounter.incrementConnectionFailedCount();
    }
    isOpen=false;
  }
 else {
    LOG.info("String_Node_Str",bucketPath);
  }
  if (timedRollFuture != null && !timedRollFuture.isDone()) {
    timedRollFuture.cancel(false);
    timedRollFuture=null;
  }
  if (idleFuture != null && !idleFuture.isDone()) {
    idleFuture.cancel(false);
    idleFuture=null;
  }
  if (bucketPath != null && fileSystem != null) {
    renameBucket();
    fileSystem=null;
  }
}

Fixed version (ground truth):
/** 
 * when stop flume, all schedulers should be canceled
 * @param cancelIdleCallback
 * @throws IOException
 * @throws InterruptedException
 */
public void close(boolean cancelIdleCallback) throws IOException, InterruptedException {
  close();
  if (cancelIdleCallback) {
    if (idleFuture != null && !idleFuture.isDone()) {
      idleFuture.cancel(false);
      idleFuture=null;
    }
  }
}
Program: 167238
Project: 167238
Buggy source:
/** 
 * try to close file, if failed too many times, just ignore  
 * @throws IOException
 * @throws InterruptedException
 */
private void graceClose() throws IOException, InterruptedException {
  try {
    close();
  }
 catch (  IOException e) {
    hdfsFailCount++;
    if (hdfsFailCount < maxHdfsFailCount) {
      LOG.warn("String_Node_Str" + hdfsFailCount);
      throw e;
    }
 else {
      isOpen=false;
      if (timedRollFuture != null && !timedRollFuture.isDone()) {
        timedRollFuture.cancel(false);
        timedRollFuture=null;
      }
      if (idleFuture != null && !idleFuture.isDone()) {
        idleFuture.cancel(false);
        idleFuture=null;
      }
      LOG.error("String_Node_Str");
    }
  }
}

Fixed version (ground truth):
/** 
 * try to close file, if failed too many times, just ignore  
 * @throws IOException
 * @throws InterruptedException
 */
private void graceClose() throws IOException, InterruptedException {
  try {
    close();
  }
 catch (  IOException e) {
    hdfsFailCount++;
    if (hdfsFailCount < maxHdfsFailCount) {
      LOG.warn("String_Node_Str" + hdfsFailCount);
      throw e;
    }
 else {
      isOpen=false;
      cancelScheduler();
      LOG.error("String_Node_Str");
    }
  }
}
Program: 167239
Project: 167239
Buggy source:
@Override public void stop(){
  for (  Entry<String,BucketWriter> entry : sfWriters.entrySet()) {
    LOG.info("String_Node_Str",entry.getKey());
    try {
      entry.getValue().close();
    }
 catch (    Exception ex) {
      LOG.warn("String_Node_Str" + entry.getKey() + "String_Node_Str"+ "String_Node_Str",ex);
      if (ex instanceof InterruptedException) {
        Thread.currentThread().interrupt();
      }
    }
  }
  ExecutorService toShutdown[]={callTimeoutPool,timedRollerPool};
  for (  ExecutorService execService : toShutdown) {
    execService.shutdown();
    try {
      while (execService.isTerminated() == false) {
        execService.awaitTermination(Math.max(defaultCallTimeout,callTimeout),TimeUnit.MILLISECONDS);
      }
    }
 catch (    InterruptedException ex) {
      LOG.warn("String_Node_Str" + execService,ex);
    }
  }
  callTimeoutPool=null;
  timedRollerPool=null;
  sfWriters.clear();
  sfWriters=null;
  sinkCounter.stop();
  super.stop();
}

Fixed version (ground truth):
@Override public void stop(){
  for (  Entry<String,BucketWriter> entry : sfWriters.entrySet()) {
    LOG.info("String_Node_Str",entry.getKey());
    try {
      entry.getValue().close(true);
    }
 catch (    Exception ex) {
      LOG.warn("String_Node_Str" + entry.getKey() + "String_Node_Str"+ "String_Node_Str",ex);
      if (ex instanceof InterruptedException) {
        Thread.currentThread().interrupt();
      }
    }
  }
  ExecutorService toShutdown[]={callTimeoutPool,timedRollerPool};
  for (  ExecutorService execService : toShutdown) {
    execService.shutdown();
    try {
      while (execService.isTerminated() == false) {
        execService.awaitTermination(Math.max(defaultCallTimeout,callTimeout),TimeUnit.MILLISECONDS);
      }
    }
 catch (    InterruptedException ex) {
      LOG.warn("String_Node_Str" + execService,ex);
    }
  }
  callTimeoutPool=null;
  timedRollerPool=null;
  sfWriters.clear();
  sfWriters=null;
  sinkCounter.stop();
  super.stop();
}
Program: 167240
Project: 167240
Buggy source:
public int compare(File a,File b){
  return new Long(a.lastModified()).compareTo(new Long(b.lastModified()));
}

Fixed version (ground truth):
public int compare(File a,File b){
  int timeComparison=new Long(a.lastModified()).compareTo(new Long(b.lastModified()));
  if (timeComparison != 0) {
    return timeComparison;
  }
 else {
    return a.getName().compareTo(b.getName());
  }
}
Program: 167241
Project: 167241
Buggy source:
/** 
 * Find and open the oldest file in the chosen directory. If the directory is empty, this will return an absent option.
 */
private Optional<FileInfo> getNextFile(){
  FileFilter filter=new FileFilter(){
    public boolean accept(    File pathName){
      if ((pathName.getName().endsWith(completedSuffix)) || (pathName.getName().startsWith("String_Node_Str"))) {
        return false;
      }
      return true;
    }
  }
;
  List<File> candidateFiles=Arrays.asList(directory.listFiles(filter));
  if (candidateFiles.isEmpty()) {
    return Optional.absent();
  }
 else {
    Collections.sort(candidateFiles,new Comparator<File>(){
      public int compare(      File a,      File b){
        return new Long(a.lastModified()).compareTo(new Long(b.lastModified()));
      }
    }
);
    File nextFile=candidateFiles.get(0);
    try {
      int bufferSize=bufferMaxLines * bufferMaxLineLength;
      BufferedReader reader=new BufferedReader(new FileReader(nextFile),bufferSize);
      reader.mark(bufferSize);
      return Optional.of(new FileInfo(nextFile,reader));
    }
 catch (    FileNotFoundException e) {
      logger.warn("String_Node_Str" + nextFile,e);
      return Optional.absent();
    }
catch (    IOException e) {
      logger.error("String_Node_Str" + nextFile,e);
      return Optional.absent();
    }
  }
}

Fixed version (ground truth):
/** 
 * Find and open the oldest file in the chosen directory. If two or more files are equally old, the file name with lower lexicographical value is returned. If the directory is empty, this will return an absent option.
 */
private Optional<FileInfo> getNextFile(){
  FileFilter filter=new FileFilter(){
    public boolean accept(    File pathName){
      if ((pathName.getName().endsWith(completedSuffix)) || (pathName.getName().startsWith("String_Node_Str"))) {
        return false;
      }
      return true;
    }
  }
;
  List<File> candidateFiles=Arrays.asList(directory.listFiles(filter));
  if (candidateFiles.isEmpty()) {
    return Optional.absent();
  }
 else {
    Collections.sort(candidateFiles,new Comparator<File>(){
      public int compare(      File a,      File b){
        int timeComparison=new Long(a.lastModified()).compareTo(new Long(b.lastModified()));
        if (timeComparison != 0) {
          return timeComparison;
        }
 else {
          return a.getName().compareTo(b.getName());
        }
      }
    }
);
    File nextFile=candidateFiles.get(0);
    try {
      int bufferSize=bufferMaxLines * bufferMaxLineLength;
      BufferedReader reader=new BufferedReader(new FileReader(nextFile),bufferSize);
      reader.mark(bufferSize);
      return Optional.of(new FileInfo(nextFile,reader));
    }
 catch (    FileNotFoundException e) {
      logger.warn("String_Node_Str" + nextFile,e);
      return Optional.absent();
    }
catch (    IOException e) {
      logger.error("String_Node_Str" + nextFile,e);
      return Optional.absent();
    }
  }
}
Program: 167242
Project: 167242
Buggy source:
/** 
 * Empty files should be skipped over when reading directory. This feature is not currently implemented.
 */
@Ignore @Test public void testBehaviorWithEmptyFile() throws IOException {
  File f1=new File(tmpDir.getAbsolutePath() + "String_Node_Str");
  Files.touch(f1);
  SpoolingFileLineReader reader=new SpoolingFileLineReader(tmpDir,completedSuffix,bufferMaxLines,bufferMaxLineLength);
  File f2=new File(tmpDir.getAbsolutePath() + "String_Node_Str");
  Files.write("String_Node_Str" + "String_Node_Str",f2,Charsets.UTF_8);
  List<String> out=reader.readLines(8);
  reader.commit();
  assertEquals(8,out.size());
  assertTrue(out.contains("String_Node_Str"));
  assertTrue(out.contains("String_Node_Str"));
  assertTrue(out.contains("String_Node_Str"));
  assertTrue(out.contains("String_Node_Str"));
  assertTrue(out.contains("String_Node_Str"));
  assertTrue(out.contains("String_Node_Str"));
  assertTrue(out.contains("String_Node_Str"));
  assertTrue(out.contains("String_Node_Str"));
  assertNull(reader.readLine());
  List<File> outFiles=Lists.newArrayList(tmpDir.listFiles());
  assertEquals(2,outFiles.size());
  assertTrue(outFiles.contains(new File(tmpDir + "String_Node_Str")));
  assertTrue(outFiles.contains(new File(tmpDir + "String_Node_Str" + completedSuffix)));
}

Fixed version (ground truth):
/** 
 * Empty files should be skipped over when reading directory. This feature is not currently implemented.
 */
@Ignore @Test public void testBehaviorWithEmptyFile() throws IOException {
  File f1=new File(tmpDir.getAbsolutePath() + "String_Node_Str");
  Files.touch(f1);
  SpoolingFileLineReader reader=new SpoolingFileLineReader(tmpDir,completedSuffix,bufferMaxLines,bufferMaxLineLength);
  File f2=new File(tmpDir.getAbsolutePath() + "String_Node_Str");
  Files.write("String_Node_Str" + "String_Node_Str",f2,Charsets.UTF_8);
  List<String> out=reader.readLines(8);
  reader.commit();
  assertEquals(8,out.size());
  assertTrue(out.contains("String_Node_Str"));
  assertTrue(out.contains("String_Node_Str"));
  assertTrue(out.contains("String_Node_Str"));
  assertTrue(out.contains("String_Node_Str"));
  assertTrue(out.contains("String_Node_Str"));
  assertTrue(out.contains("String_Node_Str"));
  assertTrue(out.contains("String_Node_Str"));
  assertTrue(out.contains("String_Node_Str"));
  assertNull(reader.readLine());
  List<File> outFiles=Lists.newArrayList(tmpDir.listFiles());
  assertEquals(2,outFiles.size());
  assertTrue(outFiles.contains(new File(tmpDir + "String_Node_Str" + completedSuffix)));
  assertTrue(outFiles.contains(new File(tmpDir + "String_Node_Str" + completedSuffix)));
}
Program: 167243
Project: 167243
Buggy source:
@Test public void testSlowSinkRoll() throws IOException, InterruptedException {
  final File f=FileUtil.mktempdir();
  RollSink snk=new RollSink(new Context(),"String_Node_Str",2000,250){
    @Override protected EventSink newSink(    Context ctx) throws IOException {
      return new EscapedCustomDfsSink(ctx,"String_Node_Str" + f.getPath(),"String_Node_Str"){
        @Override public void append(        final Event e) throws IOException, InterruptedException {
          super.append(e);
          Clock.sleep(1500);
        }
      }
;
    }
  }
;
  DummySource source=new DummySource(4);
  DirectDriver driver=new DirectDriver(source,snk);
  driver.start();
  Clock.sleep(12200);
  driver.stop();
  assertTrue(snk.getMetrics().getLongMetric(RollSink.A_ROLL_ABORTED_APPENDS) > Long.valueOf(0));
}

Fixed version (ground truth):
@Test public void testSlowSinkRoll() throws IOException, InterruptedException {
  final File f=FileUtil.mktempdir();
  final AtomicBoolean firstPass=new AtomicBoolean(true);
  RollSink snk=new RollSink(new Context(),"String_Node_Str",1000,250){
    @Override protected EventSink newSink(    Context ctx) throws IOException {
      return new EscapedCustomDfsSink(ctx,"String_Node_Str" + f.getPath(),"String_Node_Str"){
        @Override public void append(        final Event e) throws IOException, InterruptedException {
          super.append(e);
          if (firstPass.get()) {
            firstPass.set(false);
            Clock.sleep(3000);
          }
        }
      }
;
    }
  }
;
  DummySource source=new DummySource(4);
  DirectDriver driver=new DirectDriver(source,snk);
  driver.start();
  Clock.sleep(6000);
  driver.stop();
  assertTrue(snk.getMetrics().getLongMetric(RollSink.A_ROLL_ABORTED_APPENDS) > Long.valueOf(0));
}
Program: 167244
Project: 167244
Buggy source:
@Override public boolean schemaExists(){
  Connection connection=null;
  ResultSet rset=null;
  try {
    connection=dataSource.getConnection();
    Statement stmt=connection.createStatement();
    rset=stmt.executeQuery(QUREY_SYSCHEMA_FLUME);
    if (!rset.next()) {
      LOGGER.warn("String_Node_Str");
      return false;
    }
    String flumeSchemaId=rset.getString(1);
    LOGGER.debug("String_Node_Str" + flumeSchemaId);
    connection.commit();
  }
 catch (  SQLException ex) {
    try {
      connection.rollback();
    }
 catch (    SQLException ex2) {
      LOGGER.error("String_Node_Str",ex2);
    }
    throw new JdbcChannelException("String_Node_Str",ex);
  }
 finally {
    if (rset != null) {
      try {
        rset.close();
      }
 catch (      SQLException ex) {
        LOGGER.error("String_Node_Str",ex);
      }
    }
    if (connection != null) {
      try {
        connection.close();
      }
 catch (      SQLException ex) {
        LOGGER.error("String_Node_Str",ex);
      }
    }
  }
  return true;
}

Fixed version (ground truth):
@Override public boolean schemaExists(){
  Connection connection=null;
  Statement stmt=null;
  try {
    connection=dataSource.getConnection();
    stmt=connection.createStatement();
    ResultSet rset=stmt.executeQuery(QUREY_SYSCHEMA_FLUME);
    if (!rset.next()) {
      LOGGER.warn("String_Node_Str");
      return false;
    }
    String flumeSchemaId=rset.getString(1);
    LOGGER.debug("String_Node_Str" + flumeSchemaId);
    connection.commit();
  }
 catch (  SQLException ex) {
    try {
      connection.rollback();
    }
 catch (    SQLException ex2) {
      LOGGER.error("String_Node_Str",ex2);
    }
    throw new JdbcChannelException("String_Node_Str",ex);
  }
 finally {
    if (stmt != null) {
      try {
        stmt.close();
      }
 catch (      SQLException ex) {
        LOGGER.error("String_Node_Str",ex);
      }
    }
    if (connection != null) {
      try {
        connection.close();
      }
 catch (      SQLException ex) {
        LOGGER.error("String_Node_Str",ex);
      }
    }
  }
  return true;
}
Program: 167246
Project: 167246
Buggy source:
public PersistableEvent build(){
  List<HeaderEntry> bHeaders=new ArrayList<HeaderEntry>();
  for (  long headerId : bHeaderParts.keySet()) {
    HeaderPart part=bHeaderParts.get(headerId);
    bHeaders.add(part.getEntry(headerId));
  }
  PersistableEvent pe=new PersistableEvent(bEventId,bChannelName,bBasePayload,bSpillPayload,bHeaders);
  bEventId=0L;
  bChannelName=null;
  bBasePayload=null;
  bSpillPayload=null;
  bHeaderParts.clear();
  return pe;
}

Fixed version (ground truth):
public PersistableEvent build(){
  List<HeaderEntry> bHeaders=new ArrayList<HeaderEntry>();
  if (bHeaderParts != null) {
    for (    long headerId : bHeaderParts.keySet()) {
      HeaderPart part=bHeaderParts.get(headerId);
      bHeaders.add(part.getEntry(headerId));
    }
  }
  PersistableEvent pe=new PersistableEvent(bEventId,bChannelName,bBasePayload,bSpillPayload,bHeaders);
  bEventId=0L;
  bChannelName=null;
  bBasePayload=null;
  bSpillPayload=null;
  bHeaderParts=null;
  return pe;
}
Program: 167247
Project: 167247
Buggy source:
public MockEvent(byte[] payload,Map<String,String> headers){
  this.payload=payload;
  this.headers=headers;
}

Fixed version (ground truth):
public MockEvent(byte[] payload,Map<String,String> headers,String channel){
  this.payload=payload;
  this.headers=headers;
  this.channel=channel;
}
Program: 167248
Project: 167248
Buggy source:
@Test public void testCreateQueries(){
  Assert.assertEquals(DerbySchemaHandler.QUERY_CREATE_SCHEMA_FLUME,EXPECTED_QUERY_CREATE_SCHEMA_FLUME);
  Assert.assertEquals(DerbySchemaHandler.QUERY_CREATE_TABLE_FL_EVENT,EXPECTED_QUERY_CREATE_TABLE_FL_EVENT);
  Assert.assertEquals(DerbySchemaHandler.QUERY_CREATE_TABLE_FL_PLSPILL,EXPECTED_QUERY_CREATE_TABLE_FL_PLSPILL);
  Assert.assertEquals(DerbySchemaHandler.QUERY_CREATE_TABLE_FL_HEADER,EXPECTED_QUERY_CREATE_TABLE_FL_HEADER);
  Assert.assertEquals(DerbySchemaHandler.QUERY_CREATE_TABLE_FL_NMSPILL,EXPECTED_QUERY_CREATE_TABLE_FL_NMSPILL);
  Assert.assertEquals(DerbySchemaHandler.QUERY_CREATE_TABLE_FL_VLSPILL,EXPECTED_QUERY_CREATE_TABLE_FL_VLSPILL);
}

Fixed version (ground truth):
@Test public void testCreateQueries(){
  Assert.assertEquals(DerbySchemaHandler.QUERY_CREATE_SCHEMA_FLUME,EXPECTED_QUERY_CREATE_SCHEMA_FLUME);
  Assert.assertEquals(DerbySchemaHandler.QUERY_CREATE_TABLE_FL_EVENT,EXPECTED_QUERY_CREATE_TABLE_FL_EVENT);
  Assert.assertEquals(DerbySchemaHandler.QUERY_CREATE_TABLE_FL_PLSPILL,EXPECTED_QUERY_CREATE_TABLE_FL_PLSPILL);
  Assert.assertEquals(DerbySchemaHandler.QUERY_CREATE_TABLE_FL_HEADER,EXPECTED_QUERY_CREATE_TABLE_FL_HEADER);
  Assert.assertEquals(DerbySchemaHandler.QUERY_CREATE_TABLE_FL_NMSPILL,EXPECTED_QUERY_CREATE_TABLE_FL_NMSPILL);
  Assert.assertEquals(DerbySchemaHandler.QUERY_CREATE_TABLE_FL_VLSPILL,EXPECTED_QUERY_CREATE_TABLE_FL_VLSPILL);
  Assert.assertEquals(DerbySchemaHandler.COLUMN_LOOKUP_QUERY,EXPECTED_COLUMN_LOOKUP_QUERY);
  Assert.assertEquals(DerbySchemaHandler.STMT_INSERT_EVENT_BASE,EXPECTED_STMT_INSERT_EVENT_BASE);
  Assert.assertEquals(DerbySchemaHandler.STMT_INSERT_EVENT_SPILL,EXPECTED_STMT_INSERT_EVENT_SPILL);
  Assert.assertEquals(DerbySchemaHandler.STMT_INSERT_HEADER_BASE,EXPECTED_STMT_INSERT_HEADER_BASE);
  Assert.assertEquals(DerbySchemaHandler.STMT_INSERT_HEADER_NAME_SPILL,EXPECTED_STMT_INSERT_HEADER_NAME_SPILL);
  Assert.assertEquals(DerbySchemaHandler.STMT_INSERT_HEADER_VALUE_SPILL,EXPECTED_STMT_INSERT_HEADER_VALUE_SPILL);
  Assert.assertEquals(DerbySchemaHandler.STMT_FETCH_PAYLOAD_BASE,EXPECTED_STMT_FETCH_PAYLOAD_BASE);
  Assert.assertEquals(DerbySchemaHandler.STMT_FETCH_PAYLOAD_SPILL,EXPECTED_STMT_FETCH_PAYLOAD_SPILL);
  Assert.assertEquals(DerbySchemaHandler.STMT_FETCH_HEADER_BASE,EXPECTED_STMT_FETCH_HEADER_BASE);
  Assert.assertEquals(DerbySchemaHandler.STMT_FETCH_HEADER_NAME_SPILL,EXPECTED_STMT_FETCH_HEADER_NAME_SPILL);
  Assert.assertEquals(DerbySchemaHandler.STMT_FETCH_HEADER_VALUE_SPILL,EXPECTED_STMT_FETCH_HEADER_VALUE_SPILL);
  Assert.assertEquals(DerbySchemaHandler.STMT_DELETE_HEADER_VALUE_SPILL,EXPECTED_STMT_DELETE_HEADER_VALUE_SPILL);
  Assert.assertEquals(DerbySchemaHandler.STMT_DELETE_HEADER_NAME_SPILL,EXPECTED_STMT_DELETE_HEADER_NAME_SPILL);
  Assert.assertEquals(DerbySchemaHandler.STMT_DELETE_EVENT_SPILL,EXPECTED_STMT_DELETE_EVENT_SPILL);
  Assert.assertEquals(DerbySchemaHandler.STMT_DELETE_HEADER_BASE,EXPECTED_STMT_DELETE_HEADER_BASE);
  Assert.assertEquals(DerbySchemaHandler.STMT_DELETE_EVENT_BASE,EXPECTED_STMT_DELETE_EVENT_BASE);
}
Program: 167249
Project: 167249
Buggy source:
@Test public void testPeristingEvents(){
  provider=new JdbcChannelProviderImpl();
  provider.initialize(derbyProps);
  int nameLimit=ConfigurationConstants.HEADER_NAME_LENGTH_THRESHOLD;
  int th=ConfigurationConstants.PAYLOAD_LENGTH_THRESHOLD;
  byte[] s1=MockEventUtils.generatePayload(th - 1);
  Map<String,String> m1=new HashMap<String,String>();
  m1.put(MockEventUtils.generateHeaderString(1),"String_Node_Str");
  m1.put(MockEventUtils.generateHeaderString(2),"String_Node_Str");
  m1.put(MockEventUtils.generateHeaderString(3),"String_Node_Str");
  m1.put(MockEventUtils.generateHeaderString(100),"String_Node_Str");
  m1.put(MockEventUtils.generateHeaderString(nameLimit - 21),"String_Node_Str");
  m1.put(MockEventUtils.generateHeaderString(nameLimit - 2),"String_Node_Str");
  m1.put(MockEventUtils.generateHeaderString(nameLimit - 1),"String_Node_Str");
  m1.put(MockEventUtils.generateHeaderString(nameLimit),"String_Node_Str");
  m1.put(MockEventUtils.generateHeaderString(nameLimit + 1),"String_Node_Str");
  m1.put(MockEventUtils.generateHeaderString(nameLimit + 2),"String_Node_Str");
  m1.put(MockEventUtils.generateHeaderString(nameLimit + 21),"String_Node_Str");
  Event event1=new MockEvent(s1,m1);
  provider.persistEvent("String_Node_Str",event1);
  Event event2=provider.removeEvent("String_Node_Str");
  assertEquals(event1,event2);
  provider.close();
  provider=null;
}

Fixed version (ground truth):
/** 
 * creaes 1000 events split over 5 channels, stores them
 */
@Test public void testPeristingEvents(){
  provider=new JdbcChannelProviderImpl();
  provider.initialize(derbyProps);
  Map<String,List<MockEvent>> eventMap=new HashMap<String,List<MockEvent>>();
  Set<MockEvent> events=new HashSet<MockEvent>();
  for (int i=1; i < 1001; i++) {
    events.add(MockEventUtils.generateMockEvent(i,i,i,61 % i,5));
  }
  Iterator<MockEvent> meIt=events.iterator();
  while (meIt.hasNext()) {
    MockEvent me=meIt.next();
    String chName=me.getChannel();
    List<MockEvent> eventList=eventMap.get(chName);
    if (eventList == null) {
      eventList=new ArrayList<MockEvent>();
      eventMap.put(chName,eventList);
    }
    eventList.add(me);
    provider.persistEvent(me.getChannel(),me);
  }
  for (  String chName : eventMap.keySet()) {
    List<MockEvent> meList=eventMap.get(chName);
    Iterator<MockEvent> it=meList.iterator();
    while (it.hasNext()) {
      MockEvent me=it.next();
      Event event=provider.removeEvent(chName);
      assertEquals(me,event);
    }
    Event nullEvent=provider.removeEvent(chName);
    Assert.assertNull(nullEvent);
  }
  provider.close();
  provider=null;
}
Program: 167250
Project: 167250
Buggy source:
private void runTest(byte[] payload,Map<String,String> headers){
  PersistableEvent pe=new PersistableEvent("String_Node_Str",new MockEvent(payload,headers));
  Assert.assertArrayEquals(payload,pe.getBody());
  Map<String,String> h=pe.getHeaders();
  if (h == null) {
    Assert.assertTrue(headers == null || headers.size() == 0);
  }
 else {
    Assert.assertTrue(headers.size() == h.size());
    for (    String key : h.keySet()) {
      Assert.assertTrue(headers.containsKey(key));
      String value=h.get(key);
      String expectedValue=headers.remove(key);
      Assert.assertEquals(expectedValue,value);
    }
    Assert.assertTrue(headers.size() == 0);
  }
}

Fixed version (ground truth):
private void runTest(byte[] payload,Map<String,String> headers){
  PersistableEvent pe=new PersistableEvent("String_Node_Str",new MockEvent(payload,headers,null));
  Assert.assertArrayEquals(payload,pe.getBody());
  Map<String,String> h=pe.getHeaders();
  if (h == null) {
    Assert.assertTrue(headers == null || headers.size() == 0);
  }
 else {
    Assert.assertTrue(headers.size() == h.size());
    for (    String key : h.keySet()) {
      Assert.assertTrue(headers.containsKey(key));
      String value=h.get(key);
      String expectedValue=headers.remove(key);
      Assert.assertEquals(expectedValue,value);
    }
    Assert.assertTrue(headers.size() == 0);
  }
}
Program: 167251
Project: 167251
Buggy source:
@Override public void stop(){
  if (runnerThread != null) {
    runner.shouldStop.set(true);
    runnerThread.interrupt();
    while (runnerThread.isAlive()) {
      try {
        logger.debug("String_Node_Str");
        runnerThread.join(500);
      }
 catch (      InterruptedException e) {
        logger.debug("String_Node_Str",e);
      }
    }
  }
  lifecycleState=LifecycleState.STOP;
}

Fixed version (ground truth):
@Override public void stop(){
  sink.stop();
  if (runnerThread != null) {
    runner.shouldStop.set(true);
    runnerThread.interrupt();
    while (runnerThread.isAlive()) {
      try {
        logger.debug("String_Node_Str");
        runnerThread.join(500);
      }
 catch (      InterruptedException e) {
        logger.debug("String_Node_Str",e);
      }
    }
  }
  lifecycleState=LifecycleState.STOP;
}
Program: 167252
Project: 167252
Buggy source:
@Override public void start(){
  runner=new PollingRunner();
  runner.sink=sink;
  runner.counterGroup=counterGroup;
  runner.shouldStop=new AtomicBoolean();
  runnerThread=new Thread(runner);
  runnerThread.start();
  lifecycleState=LifecycleState.START;
}

Fixed version (ground truth):
@Override public void start(){
  sink.start();
  runner=new PollingRunner();
  runner.sink=sink;
  runner.counterGroup=counterGroup;
  runner.shouldStop=new AtomicBoolean();
  runnerThread=new Thread(runner);
  runnerThread.start();
  lifecycleState=LifecycleState.START;
}
Program: 167253
Project: 167253
Buggy source:
@Override public void stop(Context context) throws LifecycleException, InterruptedException {
  Preconditions.checkState(LifecycleState.START.equals(lifecycleState),"String_Node_Str");
  logger.info("String_Node_Str",this);
  driver.setShouldStop(true);
  while (driver.isAlive()) {
    logger.debug("String_Node_Str");
    try {
      driver.join();
    }
 catch (    InterruptedException e) {
      logger.error("String_Node_Str",e);
      lifecycleState=LifecycleState.ERROR;
    }
  }
  if (!lifecycleState.equals(LifecycleState.ERROR)) {
    lifecycleState=LifecycleState.STOP;
  }
}

Fixed version (ground truth):
@Override public void stop(Context context) throws LifecycleException, InterruptedException {
  Preconditions.checkState(LifecycleState.START.equals(lifecycleState),"String_Node_Str");
  logger.info("String_Node_Str",this);
  driver.setShouldStop(true);
  while (driver.isAlive()) {
    logger.debug("String_Node_Str");
    try {
      driver.join();
    }
 catch (    InterruptedException e) {
      logger.error("String_Node_Str",e);
      lifecycleState=LifecycleState.ERROR;
      break;
    }
  }
  if (!lifecycleState.equals(LifecycleState.ERROR)) {
    lifecycleState=LifecycleState.STOP;
  }
}
Program: 167254
Project: 167254
Buggy source:
public void fail(){
  try {
    LifecycleController.stopAll(new ArrayList<LifecycleAware>(supervisedProcesses.keySet()));
  }
 catch (  InterruptedException e) {
    logger.warn("String_Node_Str");
  }
  lifecycleState=LifecycleState.ERROR;
}

Fixed version (ground truth):
public synchronized void fail(){
  lifecycleState=LifecycleState.ERROR;
}
Program: 167255
Project: 167255
Buggy source:
@Override public LifecycleState getLifecycleState(){
  return lifecycleState;
}

Fixed version (ground truth):
@Override public synchronized LifecycleState getLifecycleState(){
  return lifecycleState;
}
Program: 167256
Project: 167256
Buggy source:
@Override public void stop(Context context) throws LifecycleException, InterruptedException {
  logger.info("String_Node_Str",Thread.currentThread().getId());
  monitorService.shutdown();
  while (!monitorService.isTerminated()) {
    monitorService.awaitTermination(500,TimeUnit.MILLISECONDS);
  }
synchronized (supervisedProcesses) {
    for (    final Entry<LifecycleAware,Supervisoree> entry : supervisedProcesses.entrySet()) {
      if (entry.getKey().getLifecycleState().equals(LifecycleState.START)) {
        entry.getKey().stop(context);
        LifecycleController.waitForOneOf(entry.getKey(),LifecycleState.STOP_OR_ERROR,5000);
      }
    }
  }
  lifecycleState=LifecycleState.STOP;
  logger.debug("String_Node_Str");
}

Fixed version (ground truth):
@Override public synchronized void stop(Context context) throws LifecycleException, InterruptedException {
  logger.info("String_Node_Str",Thread.currentThread().getId());
  if (monitorService != null) {
    monitorService.shutdown();
    while (!monitorService.isTerminated()) {
      monitorService.awaitTermination(500,TimeUnit.MILLISECONDS);
    }
  }
  for (  final Entry<LifecycleAware,Supervisoree> entry : supervisedProcesses.entrySet()) {
    if (entry.getKey().getLifecycleState().equals(LifecycleState.START)) {
      entry.getKey().stop(context);
      if (!LifecycleController.waitForOneOf(entry.getKey(),LifecycleState.STOP_OR_ERROR,5000)) {
        fail();
      }
    }
  }
  if (lifecycleState.equals(LifecycleState.START)) {
    lifecycleState=LifecycleState.STOP;
  }
  logger.debug("String_Node_Str");
}
Program: 167257
Project: 167257
Buggy source:
@Override public void start(Context context) throws LifecycleException, InterruptedException {
  logger.info("String_Node_Str",Thread.currentThread().getId());
synchronized (supervisedProcesses) {
    logger.debug("String_Node_Str");
    for (    Entry<LifecycleAware,Supervisoree> entry : supervisedProcesses.entrySet()) {
      MonitorRunnable monitorCheckRunnable=new MonitorRunnable();
      monitorCheckRunnable.lifecycleAware=entry.getKey();
      monitorCheckRunnable.supervisoree=entry.getValue();
      monitorService.scheduleAtFixedRate(monitorCheckRunnable,0,3,TimeUnit.SECONDS);
    }
  }
  lifecycleState=LifecycleState.START;
  logger.debug("String_Node_Str");
}

Fixed version (ground truth):
@Override public synchronized void start(Context context) throws LifecycleException, InterruptedException {
  logger.info("String_Node_Str",Thread.currentThread().getId());
  for (  Entry<LifecycleAware,Supervisoree> entry : supervisedProcesses.entrySet()) {
    MonitorRunnable monitorCheckRunnable=new MonitorRunnable();
    monitorCheckRunnable.lifecycleAware=entry.getKey();
    monitorCheckRunnable.supervisoree=entry.getValue();
    monitorService.scheduleAtFixedRate(monitorCheckRunnable,0,3,TimeUnit.SECONDS);
  }
  lifecycleState=LifecycleState.START;
  logger.debug("String_Node_Str");
}
Program: 167258
Project: 167258
Buggy source:
@Override public void stop(Context context) throws LifecycleException {
  logger.info("String_Node_Str",this);
  boolean complete=false;
  driver.stop(context);
  try {
    complete=LifecycleController.waitForOneOf(driver,new LifecycleState[]{LifecycleState.STOP,LifecycleState.ERROR});
  }
 catch (  InterruptedException e) {
    logger.debug("String_Node_Str");
    complete=false;
  }
  if (!complete) {
    logger.error("String_Node_Str",Thread.currentThread().getStackTrace());
  }
  lifecycleState=driver.getLifecycleState();
}

Fixed version (ground truth):
@Override public void stop(Context context) throws LifecycleException, InterruptedException {
  logger.info("String_Node_Str",this);
  boolean reached=false;
  try {
    driver.stop(context);
    reached=LifecycleController.waitForOneOf(driver,new LifecycleState[]{LifecycleState.STOP,LifecycleState.ERROR});
  }
 catch (  InterruptedException e) {
    logger.error("String_Node_Str");
    lifecycleState=LifecycleState.ERROR;
    throw e;
  }
  if (!reached) {
    logger.error("String_Node_Str",Thread.currentThread().getStackTrace());
  }
  lifecycleState=driver.getLifecycleState();
}
Program: 167259
Project: 167259
Buggy source:
@Override public void start(Context context) throws LifecycleException, InterruptedException {
  logger.info("String_Node_Str",this);
  Preconditions.checkState(name != null,"String_Node_Str");
  Preconditions.checkState(source != null,"String_Node_Str");
  Preconditions.checkState(sink != null,"String_Node_Str");
  driver=new ChannelDriver(name + "String_Node_Str");
  driver.setSource(source);
  driver.setSink(sink);
  driver.start(context);
  lifecycleState=LifecycleState.START;
}

Fixed version (ground truth):
@Override public void start(Context context) throws LifecycleException, InterruptedException {
  logger.info("String_Node_Str",this);
  Preconditions.checkState(name != null,"String_Node_Str");
  Preconditions.checkState(source != null,"String_Node_Str");
  Preconditions.checkState(sink != null,"String_Node_Str");
  driver=new ChannelDriver(name + "String_Node_Str");
  driver.setSource(source);
  driver.setSink(sink);
  boolean reached=false;
  try {
    driver.start(context);
    reached=LifecycleController.waitForOneOf(driver,new LifecycleState[]{LifecycleState.START,LifecycleState.ERROR});
  }
 catch (  InterruptedException e) {
    logger.error("String_Node_Str");
    driver.stop(context);
    lifecycleState=LifecycleState.ERROR;
    throw e;
  }
  if (reached) {
    lifecycleState=driver.getLifecycleState();
  }
}
Program: 167260
Project: 167260
Buggy source:
@Override public void close() throws IOException {
  List<IOException> exs=new ArrayList<IOException>(2);
  try {
    if (primaryOk)     primary.close();
  }
 catch (  IOException ex) {
    exs.add(ex);
  }
  try {
    if (backupOpen)     backup.close();
  }
 catch (  IOException ex) {
    exs.add(ex);
  }
  if (exs.size() != 0)   throw MultipleIOException.createIOException(exs);
  return;
}

Fixed version (ground truth):
@Override public void close() throws IOException {
  List<IOException> exs=new ArrayList<IOException>(2);
  try {
    if (primaryOk)     primary.close();
  }
 catch (  IOException ex) {
    exs.add(ex);
  }
  try {
    if (backupOpen)     backup.close();
  }
 catch (  IOException ex) {
    exs.add(ex);
  }
  if (exs.size() != 0) {
    throw MultipleIOException.createIOException(exs);
  }
}
Program: 167261
Project: 167261
Buggy source:
@Override public void close() throws IOException {
  List<IOException> exs=new ArrayList<IOException>(2);
  try {
    if (primaryOpen)     primary.close();
  }
 catch (  IOException ex) {
    exs.add(ex);
  }
  try {
    if (backupOpen)     backup.close();
  }
 catch (  IOException ex) {
    exs.add(ex);
  }
  if (exs.size() != 0)   throw MultipleIOException.createIOException(exs);
  return;
}

Fixed version (ground truth):
@Override public void close() throws IOException {
  List<IOException> exs=new ArrayList<IOException>(2);
  try {
    if (primaryOpen)     primary.close();
  }
 catch (  IOException ex) {
    exs.add(ex);
  }
  try {
    if (backupOpen)     backup.close();
  }
 catch (  IOException ex) {
    exs.add(ex);
  }
  if (exs.size() != 0) {
    throw MultipleIOException.createIOException(exs);
  }
}
Program: 167262
Project: 167262
Buggy source:
/** 
 * {@inheritDoc}
 */
@Override synchronized public void close() throws IOException {
  long sz=q.size();
  LOG.info(String.format("String_Node_Str",sz));
  this.svr.close();
  long maxSleep=MAX_CLOSE_SLEEP;
  long start=Clock.unixTime();
  while (q.peek() != null) {
    if (Clock.unixTime() - start > maxSleep) {
      if (sz == q.size()) {
        LOG.warn("String_Node_Str" + q.size() + "String_Node_Str");
        return;
      }
      start=Clock.unixTime();
    }
    try {
      Thread.sleep(100);
    }
 catch (    InterruptedException e) {
      LOG.error("String_Node_Str" + e.getMessage(),e);
      Thread.currentThread().interrupt();
      closed=true;
      throw new IOException(e);
    }
  }
  closed=true;
  return;
}

Fixed version (ground truth):
/** 
 * {@inheritDoc}
 */
@Override synchronized public void close() throws IOException {
  long sz=q.size();
  LOG.info(String.format("String_Node_Str",sz));
  this.svr.close();
  long maxSleep=MAX_CLOSE_SLEEP;
  long start=Clock.unixTime();
  while (q.peek() != null) {
    if (Clock.unixTime() - start > maxSleep) {
      if (sz == q.size()) {
        LOG.warn("String_Node_Str" + q.size() + "String_Node_Str");
        return;
      }
      start=Clock.unixTime();
    }
    try {
      Thread.sleep(100);
    }
 catch (    InterruptedException e) {
      LOG.error("String_Node_Str" + e.getMessage(),e);
      Thread.currentThread().interrupt();
      closed=true;
      throw new IOException(e);
    }
  }
  closed=true;
}
Program: 167264
Project: 167264
Buggy source:
public static void main(String argv[]){
  if (argv.length < 2) {
    usage();
    System.exit(-1);
  }
  boolean endless=false;
  boolean randsleep=false;
  long sleep=0;
  String props=null;
  long iters=100;
  StringBuffer b=new StringBuffer();
  for (int j=0; j < argv.length; j++) {
    if ("String_Node_Str".equals(argv[j])) {
      endless=true;
      continue;
    }
    if ("String_Node_Str".equals(argv[j])) {
      j++;
      sleep=Long.parseLong(argv[j]);
      continue;
    }
    if ("String_Node_Str".equals(argv[j])) {
      randsleep=true;
      continue;
    }
    props=argv[j];
    j++;
    iters=Long.parseLong(argv[j]);
    j++;
    boolean first=true;
    for (int i=j; i < argv.length; i++) {
      if (!first) {
        b.append("String_Node_Str");
      }
      b.append(argv[i]);
      first=false;
    }
    break;
  }
  PropertyConfigurator.configure(props);
  Logger logger=Logger.getLogger(Log4JInjector.class);
  for (long l=0; l < iters || endless; l++) {
    try {
      long thisSleep=(long)((double)sleep * (double)(randsleep ? Math.random() : 1));
      Thread.sleep(thisSleep);
    }
 catch (    InterruptedException e) {
      e.printStackTrace();
    }
    logger.warn("String_Node_Str" + l + "String_Node_Str"+ b);
  }
}

Fixed version (ground truth):
public static void main(String argv[]){
  if (argv.length < 2) {
    usage();
    System.exit(-1);
  }
  boolean endless=false;
  boolean randsleep=false;
  long sleep=0;
  String props=null;
  long iters=100;
  StringBuffer b=new StringBuffer();
  for (int j=0; j < argv.length; j++) {
    if ("String_Node_Str".equals(argv[j])) {
      endless=true;
      continue;
    }
    if ("String_Node_Str".equals(argv[j])) {
      j++;
      sleep=Long.parseLong(argv[j]);
      continue;
    }
    if ("String_Node_Str".equals(argv[j])) {
      randsleep=true;
      continue;
    }
    props=argv[j];
    j++;
    iters=Long.parseLong(argv[j]);
    j++;
    boolean first=true;
    for (int i=j; i < argv.length; i++) {
      if (!first) {
        b.append(' ');
      }
      b.append(argv[i]);
      first=false;
    }
    break;
  }
  PropertyConfigurator.configure(props);
  Logger logger=Logger.getLogger(Log4JInjector.class);
  for (long l=0; l < iters || endless; l++) {
    try {
      long thisSleep=(long)((double)sleep * (double)(randsleep ? Math.random() : 1));
      Thread.sleep(thisSleep);
    }
 catch (    InterruptedException e) {
      e.printStackTrace();
    }
    logger.warn("String_Node_Str" + l + "String_Node_Str"+ b);
  }
}
Program: 167265
Project: 167265
Buggy source:
@Override public void close() throws IOException {
  if (server == null) {
    LOG.info(String.format("String_Node_Str",port));
    return;
  }
  server.stop();
  LOG.info(String.format("String_Node_Str",port));
  return;
}

Fixed version (ground truth):
@Override public void close() throws IOException {
  if (server == null) {
    LOG.info(String.format("String_Node_Str",port));
    return;
  }
  server.stop();
  LOG.info(String.format("String_Node_Str",port));
}
Program: 167266
Project: 167266
Buggy source:
@Override synchronized public void close() throws IOException {
  if (server == null) {
    LOG.info(String.format("String_Node_Str",port));
    return;
  }
  server.stop();
  LOG.info(String.format("String_Node_Str",port));
  long sz=q.size();
  LOG.info(String.format("String_Node_Str",sz));
  long maxSleep=MAX_CLOSE_SLEEP;
  long start=Clock.unixTime();
  while (q.peek() != null) {
    if (Clock.unixTime() - start > maxSleep) {
      if (sz == q.size()) {
        LOG.warn("String_Node_Str" + q.size() + "String_Node_Str");
        return;
      }
      start=Clock.unixTime();
    }
    try {
      Thread.sleep(100);
    }
 catch (    InterruptedException e) {
      LOG.error("String_Node_Str" + e.getMessage(),e);
      Thread.currentThread().interrupt();
      closed=true;
      throw new IOException(e);
    }
  }
  closed=true;
  return;
}

Fixed version (ground truth):
@Override synchronized public void close() throws IOException {
  if (server == null) {
    LOG.info(String.format("String_Node_Str",port));
    return;
  }
  server.stop();
  LOG.info(String.format("String_Node_Str",port));
  long sz=q.size();
  LOG.info(String.format("String_Node_Str",sz));
  long maxSleep=MAX_CLOSE_SLEEP;
  long start=Clock.unixTime();
  while (q.peek() != null) {
    if (Clock.unixTime() - start > maxSleep) {
      if (sz == q.size()) {
        LOG.warn("String_Node_Str" + q.size() + "String_Node_Str");
        return;
      }
      start=Clock.unixTime();
    }
    try {
      Thread.sleep(100);
    }
 catch (    InterruptedException e) {
      LOG.error("String_Node_Str" + e.getMessage(),e);
      Thread.currentThread().interrupt();
      closed=true;
      throw new IOException(e);
    }
  }
  closed=true;
}
Program: 167267
Project: 167267
Buggy source:
void exec(Command cmd) throws MasterExecException {
  Execable ex=cmds.get(cmd.getCommand());
  if (ex == null) {
    throw new MasterExecException("String_Node_Str" + cmd + "String_Node_Str",null);
  }
  LOG.info("String_Node_Str" + cmd);
  try {
    ex.exec(cmd.getArgs());
  }
 catch (  MasterExecException e) {
    throw e;
  }
catch (  IOException e) {
    throw new MasterExecException(e.getMessage(),e);
  }
  return;
}

Fixed version (ground truth):
void exec(Command cmd) throws MasterExecException {
  Execable ex=cmds.get(cmd.getCommand());
  if (ex == null) {
    throw new MasterExecException("String_Node_Str" + cmd + "String_Node_Str",null);
  }
  LOG.info("String_Node_Str" + cmd);
  try {
    ex.exec(cmd.getArgs());
  }
 catch (  MasterExecException e) {
    throw e;
  }
catch (  IOException e) {
    throw new MasterExecException(e.getMessage(),e);
  }
}
Program: 167268
Project: 167268
Buggy source:
/** 
 * checks to see if any node's last heart beat was too long ago
 */
public void checkup(){
  long now=Clock.unixTime();
  HashMap<String,NodeStatus> ss=null;
synchronized (statuses) {
    ss=new HashMap<String,NodeStatus>(statuses);
  }
  int maxMissed=FlumeConfiguration.get().getMasterMaxMissedheartbeats();
  long timeout=FlumeConfiguration.get().getConfigHeartbeatPeriod() * maxMissed;
  for (  Entry<String,NodeStatus> e : ss.entrySet()) {
    NodeStatus ns=e.getValue();
    long delta=now - ns.lastseen;
    if (delta > timeout) {
      ns.state=NodeState.LOST;
    }
    String expectedPhys=FlumeMaster.getInstance().getSpecMan().getPhysicalNode(e.getKey());
    if (expectedPhys == null || !expectedPhys.equals(ns.physicalNode)) {
      ns.state=NodeState.DECOMMISSIONED;
    }
  }
  return;
}

Fixed version (ground truth):
/** 
 * checks to see if any node's last heart beat was too long ago
 */
public void checkup(){
  long now=Clock.unixTime();
  HashMap<String,NodeStatus> ss=null;
synchronized (statuses) {
    ss=new HashMap<String,NodeStatus>(statuses);
  }
  int maxMissed=FlumeConfiguration.get().getMasterMaxMissedheartbeats();
  long timeout=FlumeConfiguration.get().getConfigHeartbeatPeriod() * maxMissed;
  for (  Entry<String,NodeStatus> e : ss.entrySet()) {
    NodeStatus ns=e.getValue();
    long delta=now - ns.lastseen;
    if (delta > timeout) {
      ns.state=NodeState.LOST;
    }
    String expectedPhys=FlumeMaster.getInstance().getSpecMan().getPhysicalNode(e.getKey());
    if (expectedPhys == null || !expectedPhys.equals(ns.physicalNode)) {
      ns.state=NodeState.DECOMMISSIONED;
    }
  }
}
Program: 167269
Project: 167269
Buggy source:
/** 
 * Converts a nodemap into an Avro-serialized byte array
 */
static protected byte[] serializeNodeMap(ListMultimap<String,String> nodeMap) throws IOException {
  DatumWriter<AvroFlumeNodeMap> datumWriter=new SpecificDatumWriter<AvroFlumeNodeMap>();
  AvroFlumeNodeMap avromap=new AvroFlumeNodeMap();
  Map<CharSequence,List<CharSequence>> map=new HashMap<CharSequence,List<CharSequence>>();
  for (  Entry<String,Collection<String>> e : nodeMap.asMap().entrySet()) {
    String name=e.getKey();
    GenericArray<CharSequence> out=new GenericData.Array<CharSequence>(e.getValue().size(),Schema.createArray(Schema.create(Type.STRING)));
    for (    String s : e.getValue()) {
      out.add(new String(s));
    }
    map.put(new String(name),out);
  }
  avromap.nodemap=map;
  datumWriter.setSchema(avromap.getSchema());
  ByteArrayOutputStream baos=new ByteArrayOutputStream();
  DataFileWriter<AvroFlumeNodeMap> fileWriter=new DataFileWriter<AvroFlumeNodeMap>(datumWriter);
  fileWriter.create(avromap.getSchema(),baos);
  fileWriter.append(avromap);
  fileWriter.close();
  return baos.toByteArray();
}

Fixed version (ground truth):
/** 
 * Converts a nodemap into an Avro-serialized byte array
 */
static protected byte[] serializeNodeMap(ListMultimap<String,String> nodeMap) throws IOException {
  DatumWriter<AvroFlumeNodeMap> datumWriter=new SpecificDatumWriter<AvroFlumeNodeMap>();
  AvroFlumeNodeMap avromap=new AvroFlumeNodeMap();
  Map<CharSequence,List<CharSequence>> map=new HashMap<CharSequence,List<CharSequence>>();
  for (  Entry<String,Collection<String>> e : nodeMap.asMap().entrySet()) {
    String name=e.getKey();
    GenericArray<CharSequence> out=new GenericData.Array<CharSequence>(e.getValue().size(),Schema.createArray(Schema.create(Type.STRING)));
    for (    String s : e.getValue()) {
      out.add(new String(s));
    }
    map.put(name,out);
  }
  avromap.nodemap=map;
  datumWriter.setSchema(avromap.getSchema());
  ByteArrayOutputStream baos=new ByteArrayOutputStream();
  DataFileWriter<AvroFlumeNodeMap> fileWriter=new DataFileWriter<AvroFlumeNodeMap>(datumWriter);
  fileWriter.create(avromap.getSchema(),baos);
  fileWriter.append(avromap);
  fileWriter.close();
  return baos.toByteArray();
}
Program: 167270
Project: 167270
Buggy source:
/** 
 * Converts a ChokeMap into an Avro-serialized byte array
 */
static protected byte[] serializeChokeMap(Map<String,Map<String,Integer>> chokeMap) throws IOException {
  DatumWriter<AvroFlumeChokeMap> datumWriter=new SpecificDatumWriter<AvroFlumeChokeMap>();
  AvroFlumeChokeMap avromap=new AvroFlumeChokeMap();
  Map<CharSequence,Map<CharSequence,Integer>> map=new HashMap<CharSequence,Map<CharSequence,Integer>>();
  for (  Entry<String,Map<String,Integer>> e : chokeMap.entrySet()) {
    String name=e.getKey();
    HashMap<CharSequence,Integer> tempMap=new HashMap<CharSequence,Integer>();
    for (    Entry<String,Integer> mape : e.getValue().entrySet()) {
      tempMap.put(new String(mape.getKey()),mape.getValue());
    }
    map.put(new String(name),tempMap);
  }
  avromap.chokemap=map;
  datumWriter.setSchema(avromap.getSchema());
  ByteArrayOutputStream baos=new ByteArrayOutputStream();
  DataFileWriter<AvroFlumeChokeMap> fileWriter=new DataFileWriter<AvroFlumeChokeMap>(datumWriter);
  fileWriter.create(avromap.getSchema(),baos);
  fileWriter.append(avromap);
  fileWriter.close();
  return baos.toByteArray();
}

Fixed version (ground truth):
/** 
 * Converts a ChokeMap into an Avro-serialized byte array
 */
static protected byte[] serializeChokeMap(Map<String,Map<String,Integer>> chokeMap) throws IOException {
  DatumWriter<AvroFlumeChokeMap> datumWriter=new SpecificDatumWriter<AvroFlumeChokeMap>();
  AvroFlumeChokeMap avromap=new AvroFlumeChokeMap();
  Map<CharSequence,Map<CharSequence,Integer>> map=new HashMap<CharSequence,Map<CharSequence,Integer>>();
  for (  Entry<String,Map<String,Integer>> e : chokeMap.entrySet()) {
    String name=e.getKey();
    HashMap<CharSequence,Integer> tempMap=new HashMap<CharSequence,Integer>();
    for (    Entry<String,Integer> mape : e.getValue().entrySet()) {
      tempMap.put(new String(mape.getKey()),mape.getValue());
    }
    map.put(name,tempMap);
  }
  avromap.chokemap=map;
  datumWriter.setSchema(avromap.getSchema());
  ByteArrayOutputStream baos=new ByteArrayOutputStream();
  DataFileWriter<AvroFlumeChokeMap> fileWriter=new DataFileWriter<AvroFlumeChokeMap>(datumWriter);
  fileWriter.create(avromap.getSchema(),baos);
  fileWriter.append(avromap);
  fileWriter.close();
  return baos.toByteArray();
}
Program: 167271
Project: 167271
Buggy source:
@Override synchronized public void removeLogicalNode(String logicNode) throws IOException {
  String oldflow=getFlowId(logicNode);
  parent.removeLogicalNode(logicNode);
  flows.get(oldflow).removeLogicalNode(logicNode);
}

Fixed version (ground truth):
@Override synchronized public void removeLogicalNode(String logicNode) throws IOException {
  String oldflow=getFlowId(logicNode);
  parent.removeLogicalNode(logicNode);
  ConfigurationManager flowCfg=flows.get(oldflow);
  if (flowCfg != null) {
    flowCfg.removeLogicalNode(logicNode);
  }
}