Program: 57858
Project: 57858
Buggy source:
/** 
 * test listCorruptFileBlocks in DistributedFileSystem
 */
@Test public void testlistCorruptFileBlocksDFS() throws Exception {
  Configuration conf=new Configuration();
  conf.setLong("String_Node_Str",1000);
  conf.setInt("String_Node_Str",1);
  FileSystem fs=null;
  MiniDFSCluster cluster=null;
  try {
    cluster=new MiniDFSCluster.Builder(conf).build();
    cluster.waitActive();
    fs=cluster.getFileSystem();
    DistributedFileSystem dfs=(DistributedFileSystem)fs;
    DFSTestUtil util=new DFSTestUtil("String_Node_Str",3,1,1024);
    util.createFiles(fs,"String_Node_Str");
    final NameNode namenode=cluster.getNameNode();
    RemoteIterator<Path> corruptFileBlocks=dfs.listCorruptFileBlocks(new Path("String_Node_Str"));
    int numCorrupt=countPaths(corruptFileBlocks);
    assertTrue(numCorrupt == 0);
    File baseDir=new File(System.getProperty("String_Node_Str","String_Node_Str"),"String_Node_Str");
    for (int i=0; i < 8; i++) {
      File data_dir=new File(baseDir,"String_Node_Str" + (i + 1) + MiniDFSCluster.FINALIZED_DIR_NAME);
      File[] blocks=data_dir.listFiles();
      if (blocks == null)       continue;
      for (int idx=0; idx < blocks.length; idx++) {
        if (!blocks[idx].getName().startsWith("String_Node_Str")) {
          continue;
        }
        LOG.info("String_Node_Str" + blocks[idx].getName());
        assertTrue("String_Node_Str",blocks[idx].delete());
      }
    }
    int count=0;
    corruptFileBlocks=dfs.listCorruptFileBlocks(new Path("String_Node_Str"));
    numCorrupt=countPaths(corruptFileBlocks);
    while (numCorrupt < 3) {
      Thread.sleep(1000);
      corruptFileBlocks=dfs.listCorruptFileBlocks(new Path("String_Node_Str"));
      numCorrupt=countPaths(corruptFileBlocks);
      count++;
      if (count > 30)       break;
    }
    LOG.info("String_Node_Str" + numCorrupt);
    assertTrue(numCorrupt == 3);
    util.cleanup(fs,"String_Node_Str");
    util.cleanup(fs,"String_Node_Str");
  }
  finally {
    if (cluster != null) {
      cluster.shutdown();
    }
  }
}

Fixed version (ground truth):
/** 
 * test listCorruptFileBlocks in DistributedFileSystem
 */
@Test public void testlistCorruptFileBlocksDFS() throws Exception {
  Configuration conf=new Configuration();
  conf.setLong("String_Node_Str",1000);
  conf.setInt("String_Node_Str",1);
  FileSystem fs=null;
  MiniDFSCluster cluster=null;
  try {
    cluster=new MiniDFSCluster.Builder(conf).build();
    cluster.waitActive();
    fs=cluster.getFileSystem();
    DistributedFileSystem dfs=(DistributedFileSystem)fs;
    DFSTestUtil util=new DFSTestUtil("String_Node_Str",3,1,1024);
    util.createFiles(fs,"String_Node_Str");
    RemoteIterator<Path> corruptFileBlocks=dfs.listCorruptFileBlocks(new Path("String_Node_Str"));
    int numCorrupt=countPaths(corruptFileBlocks);
    assertTrue(numCorrupt == 0);
    String bpid=cluster.getNamesystem().getBlockPoolId();
    for (int i=0; i < 2; i++) {
      File storageDir=MiniDFSCluster.getStorageDir(0,i);
      File data_dir=MiniDFSCluster.getFinalizedDir(storageDir,bpid);
      File[] blocks=data_dir.listFiles();
      if (blocks == null)       continue;
      for (int idx=0; idx < blocks.length; idx++) {
        if (!blocks[idx].getName().startsWith("String_Node_Str")) {
          continue;
        }
        LOG.info("String_Node_Str" + blocks[idx].getName());
        assertTrue("String_Node_Str",blocks[idx].delete());
      }
    }
    int count=0;
    corruptFileBlocks=dfs.listCorruptFileBlocks(new Path("String_Node_Str"));
    numCorrupt=countPaths(corruptFileBlocks);
    while (numCorrupt < 3) {
      Thread.sleep(1000);
      corruptFileBlocks=dfs.listCorruptFileBlocks(new Path("String_Node_Str"));
      numCorrupt=countPaths(corruptFileBlocks);
      count++;
      if (count > 30)       break;
    }
    LOG.info("String_Node_Str" + numCorrupt);
    assertTrue(numCorrupt == 3);
    util.cleanup(fs,"String_Node_Str");
    util.cleanup(fs,"String_Node_Str");
  }
  finally {
    if (cluster != null) {
      cluster.shutdown();
    }
  }
}