Program: 4839
Project: 4839
Buggy source:
/** 
 * Unit test.  REQUIRES JAVA2 FOR createTempFile Note that many tests are STRONGER than required by the specifications for simplicity.  For example, we assume an order on the values returned by getSharedFiles. 
 */
public void testLegacy(){
  File f1=null;
  File f2=null;
  File f3=null;
  File f4=null;
  File f5=null;
  File f6=null;
  try {
    f1=createNewTestFile(1);
    File directory=FileManager.getParentFile(f1);
    FileManager fman=new FileManager();
    File[] files=fman.getSharedFiles(directory);
    assertTrue(files == null);
    SettingsManager settings=SettingsManager.instance();
    settings.setExtensions("String_Node_Str");
    settings.setDirectories(new File[]{directory});
    fman.loadSettings(false);
    try {
      Thread.sleep(1000);
    }
 catch (    InterruptedException e) {
    }
    f2=createNewTestFile(3);
    f3=createNewTestFile(11);
    assertTrue(fman.getNumFiles() + "String_Node_Str",fman.getNumFiles() == 1);
    assertTrue(fman.getSize() + "String_Node_Str",fman.getSize() == 1);
    Response[] responses=fman.query(new QueryRequest((byte)3,0,"String_Node_Str"));
    assertTrue(responses.length == 1);
    assertTrue(fman.removeFileIfShared(f3) == false);
    responses=fman.query(new QueryRequest((byte)3,0,"String_Node_Str"));
    assertTrue(responses.length == 1);
    assertTrue(fman.getSize() == 1);
    assertTrue(fman.getNumFiles() == 1);
    fman.get(0);
    files=fman.getSharedFiles(directory);
    assertTrue(files.length == 1);
    assertTrue(files[0] + "String_Node_Str" + f1,files[0].equals(f1));
    files=fman.getSharedFiles(FileManager.getParentFile(directory));
    assertTrue(files == null);
    assertTrue(fman.addFileIfShared(new File("String_Node_Str")) == false);
    assertTrue(fman.addFileIfShared(f2) == true);
    assertTrue(fman.getNumFiles() + "String_Node_Str",fman.getNumFiles() == 2);
    assertTrue(fman.getSize() + "String_Node_Str",fman.getSize() == 4);
    responses=fman.query(new QueryRequest((byte)3,0,"String_Node_Str"));
    assertTrue(responses[0].getIndex() != responses[1].getIndex());
    for (int i=0; i < responses.length; i++) {
      assertTrue(responses[i].getIndex() == 0 || responses[i].getIndex() == 1);
    }
    files=fman.getSharedFiles(directory);
    assertTrue(files.length == 2);
    assertTrue(files[0] + "String_Node_Str" + f1,files[0].equals(f1));
    assertTrue(files[1] + "String_Node_Str" + f2,files[1].equals(f2));
    assertTrue(fman.removeFileIfShared(f3) == false);
    assertTrue(fman.removeFileIfShared(f2) == true);
    assertTrue(fman.getSize() == 1);
    assertTrue(fman.getNumFiles() == 1);
    responses=fman.query(new QueryRequest((byte)3,0,"String_Node_Str"));
    assertTrue(responses.length == 1);
    files=fman.getSharedFiles(directory);
    assertTrue(files.length == 1);
    assertTrue(files[0] + "String_Node_Str" + f1,files[0].equals(f1));
    assertTrue(fman.addFileIfShared(f3) == true);
    assertTrue("String_Node_Str" + fman.getSize(),fman.getSize() == 12);
    assertTrue("String_Node_Str" + fman.getNumFiles(),fman.getNumFiles() == 2);
    responses=fman.query(new QueryRequest((byte)3,0,"String_Node_Str"));
    assertTrue("String_Node_Str" + responses.length,responses.length == 2);
    assertTrue(responses[0].getIndex() != 1);
    assertTrue(responses[1].getIndex() != 1);
    fman.get(0);
    fman.get(2);
    try {
      fman.get(1);
      assertTrue(false);
    }
 catch (    IndexOutOfBoundsException e) {
    }
    responses=fman.query(new QueryRequest((byte)3,0,"String_Node_Str"));
    assertTrue("String_Node_Str" + responses.length,responses.length == 2);
    files=fman.getSharedFiles(directory);
    assertTrue(files.length == 2);
    assertTrue(files[0] + "String_Node_Str" + f1,files[0].equals(f1));
    assertTrue(files[1] + "String_Node_Str" + f3,files[1].equals(f3));
    files=fman.getSharedFiles(null);
    assertTrue(files.length == 2);
    assertTrue(files[0] + "String_Node_Str" + f1,files[0].equals(f1));
    assertTrue(files[1] + "String_Node_Str" + f3,files[1].equals(f3));
    assertTrue(fman.renameFileIfShared(f2,f2) == false);
    assertTrue(fman.renameFileIfShared(f1,f2) == true);
    files=fman.getSharedFiles(directory);
    assertTrue(files.length == 2);
    assertTrue(files[0].equals(f3));
    assertTrue(files[1].equals(f2));
    assertTrue(fman.renameFileIfShared(f2,new File("String_Node_Str")) == false);
    files=fman.getSharedFiles(directory);
    assertTrue(files.length == 1);
    assertTrue(files[0].equals(f3));
    f4=createFakeTestFile(Integer.MAX_VALUE + 1l);
    assertTrue(fman.addFileIfShared(f4) == false);
    assertTrue(fman.getNumFiles() == 1);
    assertTrue(fman.getSize() == 11);
    f5=createFakeTestFile(Integer.MAX_VALUE - 1);
    f6=createFakeTestFile(Integer.MAX_VALUE);
    assertTrue(fman.addFileIfShared(f5) == true);
    assertTrue(fman.addFileIfShared(f6) == true);
    assertTrue(fman.getNumFiles() == 3);
    assertTrue(fman.getSize() == Integer.MAX_VALUE);
    responses=fman.query(new QueryRequest((byte)3,(byte)0,"String_Node_Str"));
    assertTrue(responses.length == 3);
    assertTrue(responses[0].getName().equals(f3.getName()));
    assertTrue(responses[1].getName().equals(f5.getName()));
    assertTrue(responses[2].getName().equals(f6.getName()));
  }
  finally {
    if (f1 != null)     f1.delete();
    if (f2 != null)     f2.delete();
    if (f3 != null)     f3.delete();
    if (f4 != null)     f4.delete();
    if (f5 != null)     f5.delete();
    if (f6 != null)     f6.delete();
  }
}

Fixed version (ground truth):
/** 
 * Unit test.  REQUIRES JAVA2 FOR createTempFile Note that many tests are STRONGER than required by the specifications for simplicity.  For example, we assume an order on the values returned by getSharedFiles. 
 */
public void testLegacy(){
  File f1=null;
  File f2=null;
  File f3=null;
  File f4=null;
  File f5=null;
  File f6=null;
  try {
    f1=createNewTestFile(1);
    File directory=FileManager.getParentFile(f1);
    FileManager fman=new FileManager();
    File[] files=fman.getSharedFiles(directory);
    assertTrue(files == null);
    SettingsManager settings=SettingsManager.instance();
    settings.setExtensions("String_Node_Str");
    settings.setDirectories(new File[]{directory});
    fman.loadSettings(false);
    try {
      Thread.sleep(1000);
    }
 catch (    InterruptedException e) {
    }
    f2=createNewTestFile(3);
    f3=createNewTestFile(11);
    assertEquals(1,fman.getNumFiles());
    assertTrue(fman.getSize() + "String_Node_Str",fman.getSize() == 1);
    Response[] responses=fman.query(new QueryRequest((byte)3,0,"String_Node_Str"));
    assertTrue(responses.length == 1);
    assertTrue(fman.removeFileIfShared(f3) == false);
    responses=fman.query(new QueryRequest((byte)3,0,"String_Node_Str"));
    assertTrue(responses.length == 1);
    assertTrue(fman.getSize() == 1);
    assertTrue(fman.getNumFiles() == 1);
    fman.get(0);
    files=fman.getSharedFiles(directory);
    assertTrue(files.length == 1);
    assertTrue(files[0] + "String_Node_Str" + f1,files[0].equals(f1));
    files=fman.getSharedFiles(FileManager.getParentFile(directory));
    assertTrue(files == null);
    assertTrue(fman.addFileIfShared(new File("String_Node_Str")) == false);
    assertTrue(fman.addFileIfShared(f2) == true);
    assertTrue(fman.getNumFiles() + "String_Node_Str",fman.getNumFiles() == 2);
    assertTrue(fman.getSize() + "String_Node_Str",fman.getSize() == 4);
    responses=fman.query(new QueryRequest((byte)3,0,"String_Node_Str"));
    assertTrue(responses[0].getIndex() != responses[1].getIndex());
    for (int i=0; i < responses.length; i++) {
      assertTrue(responses[i].getIndex() == 0 || responses[i].getIndex() == 1);
    }
    files=fman.getSharedFiles(directory);
    assertTrue(files.length == 2);
    assertTrue(files[0] + "String_Node_Str" + f1,files[0].equals(f1));
    assertTrue(files[1] + "String_Node_Str" + f2,files[1].equals(f2));
    assertTrue(fman.removeFileIfShared(f3) == false);
    assertTrue(fman.removeFileIfShared(f2) == true);
    assertTrue(fman.getSize() == 1);
    assertTrue(fman.getNumFiles() == 1);
    responses=fman.query(new QueryRequest((byte)3,0,"String_Node_Str"));
    assertTrue(responses.length == 1);
    files=fman.getSharedFiles(directory);
    assertTrue(files.length == 1);
    assertTrue(files[0] + "String_Node_Str" + f1,files[0].equals(f1));
    assertTrue(fman.addFileIfShared(f3) == true);
    assertTrue("String_Node_Str" + fman.getSize(),fman.getSize() == 12);
    assertTrue("String_Node_Str" + fman.getNumFiles(),fman.getNumFiles() == 2);
    responses=fman.query(new QueryRequest((byte)3,0,"String_Node_Str"));
    assertTrue("String_Node_Str" + responses.length,responses.length == 2);
    assertTrue(responses[0].getIndex() != 1);
    assertTrue(responses[1].getIndex() != 1);
    fman.get(0);
    fman.get(2);
    try {
      fman.get(1);
      assertTrue(false);
    }
 catch (    IndexOutOfBoundsException e) {
    }
    responses=fman.query(new QueryRequest((byte)3,0,"String_Node_Str"));
    assertTrue("String_Node_Str" + responses.length,responses.length == 2);
    files=fman.getSharedFiles(directory);
    assertTrue(files.length == 2);
    assertTrue(files[0] + "String_Node_Str" + f1,files[0].equals(f1));
    assertTrue(files[1] + "String_Node_Str" + f3,files[1].equals(f3));
    files=fman.getSharedFiles(null);
    assertTrue(files.length == 2);
    assertTrue(files[0] + "String_Node_Str" + f1,files[0].equals(f1));
    assertTrue(files[1] + "String_Node_Str" + f3,files[1].equals(f3));
    assertTrue(fman.renameFileIfShared(f2,f2) == false);
    assertTrue(fman.renameFileIfShared(f1,f2) == true);
    files=fman.getSharedFiles(directory);
    assertTrue(files.length == 2);
    assertTrue(files[0].equals(f3));
    assertTrue(files[1].equals(f2));
    assertTrue(fman.renameFileIfShared(f2,new File("String_Node_Str")) == false);
    files=fman.getSharedFiles(directory);
    assertTrue(files.length == 1);
    assertTrue(files[0].equals(f3));
    f4=createFakeTestFile(Integer.MAX_VALUE + 1l);
    assertTrue(fman.addFileIfShared(f4) == false);
    assertTrue(fman.getNumFiles() == 1);
    assertTrue(fman.getSize() == 11);
    f5=createFakeTestFile(Integer.MAX_VALUE - 1);
    f6=createFakeTestFile(Integer.MAX_VALUE);
    assertTrue(fman.addFileIfShared(f5) == true);
    assertTrue(fman.addFileIfShared(f6) == true);
    assertTrue(fman.getNumFiles() == 3);
    assertTrue(fman.getSize() == Integer.MAX_VALUE);
    responses=fman.query(new QueryRequest((byte)3,(byte)0,"String_Node_Str"));
    assertTrue(responses.length == 3);
    assertTrue(responses[0].getName().equals(f3.getName()));
    assertTrue(responses[1].getName().equals(f5.getName()));
    assertTrue(responses[2].getName().equals(f6.getName()));
  }
  finally {
    if (f1 != null)     f1.delete();
    if (f2 != null)     f2.delete();
    if (f3 != null)     f3.delete();
    if (f4 != null)     f4.delete();
    if (f5 != null)     f5.delete();
    if (f6 != null)     f6.delete();
  }
}