nus-yam/ex-repair huggingface dataset:
Program: 4917
Project: 4917
Buggy source:
/** 
 * Adds the passed endpoint to the set of hosts maintained. The endpoint  may not get added due to various reasons (including it might be our address itself, we migt be connected to it etc.). Also adding this endpoint may lead to the removal of some other endpoint from the cache.
 * @param e Endpoint to be added
 * @return true iff e was actually added
 */
private boolean add(Endpoint e){
  if (manager.isConnected(e))   return false;
  if (isMe(e.getHostname(),e.getPort()))   return false;
  try {
    if (isRouter(e.getHostBytes()))     return false;
  }
 catch (  UnknownHostException uhe) {
    return false;
  }
  boolean ret=false;
  boolean notifyGUI=false;
synchronized (this) {
    if (!(set.contains(e))) {
      ret=true;
      set.add(e);
      Object ejected=queue.insert(e,e.getWeight());
      if (ejected != null)       set.remove(ejected);
      if (ejected == null)       notifyGUI=true;
      this.notify();
    }
  }
synchronized (gotGoodPongLock) {
    gotGoodPong=true;
    gotGoodPongLock.notify();
  }
  if (alwaysNotifyKnownHost) {
    callback.knownHost(e);
  }
 else {
    if (notifyGUI)     callback.knownHost(e);
  }
  return ret;
}

Fixed version (ground truth):
/** 
 * Adds the passed endpoint to the set of hosts maintained. The endpoint  may not get added due to various reasons (including it might be our address itself, we migt be connected to it etc.). Also adding this endpoint may lead to the removal of some other endpoint from the cache.
 * @param e Endpoint to be added
 * @return true iff e was actually added
 */
private boolean add(Endpoint e){
  if (isMe(e.getHostname(),e.getPort()))   return false;
  try {
    if (isRouter(e.getHostBytes()))     return false;
  }
 catch (  UnknownHostException uhe) {
    return false;
  }
  boolean ret=false;
  boolean notifyGUI=false;
synchronized (this) {
    if (!(set.contains(e))) {
      ret=true;
      set.add(e);
      Object ejected=queue.insert(e,e.getWeight());
      if (ejected != null)       set.remove(ejected);
      if (ejected == null)       notifyGUI=true;
      this.notify();
    }
  }
synchronized (gotGoodPongLock) {
    gotGoodPong=true;
    gotGoodPongLock.notify();
  }
  if (alwaysNotifyKnownHost) {
    callback.knownHost(e);
  }
 else {
    if (notifyGUI)     callback.knownHost(e);
  }
  return ret;
}
Program: 4918
Project: 4918
Buggy source:
private static void testAcceptI(RouterService rs,TestMessageRouter router,String host,int port){
  System.out.println("String_Node_Str");
  for (int i=0; i < 100; i++)   router.addHost("String_Node_Str" + i,6340,true);
  Connection c=testLimit(host,port,LEAF,LEAF_CONNECTIONS,REJECT_503);
  testPong(c,true);
  testLimit(host,port,OLD_06,ConnectionManager.DESIRED_OLD_CONNECTIONS,REJECT_503);
  testPong(c,true);
  testLimit(host,port,ULTRAPEER,KEEP_ALIVE - ConnectionManager.DESIRED_OLD_CONNECTIONS,REJECT_503);
  testPong(c,false);
}

Fixed version (ground truth):
private static void testAcceptI(TestRouterService rs,TestMessageRouter router,String host,int port){
  System.out.println("String_Node_Str");
  Assert.that(!rs.getConnectionManager().isConnected(new Endpoint("String_Node_Str",6346)));
  for (int i=0; i < 100; i++)   router.addHost("String_Node_Str" + i,6340,true);
  Connection c=testLimit(host,port,LEAF,LEAF_CONNECTIONS,REJECT_503);
  Assert.that(rs.getConnectionManager().isConnected(new Endpoint("String_Node_Str",17)));
  Assert.that(!rs.getConnectionManager().isConnected(new Endpoint("String_Node_Str",6346)));
  testPong(c,true);
  testLimit(host,port,OLD_06,ConnectionManager.DESIRED_OLD_CONNECTIONS,REJECT_503);
  testPong(c,true);
  testLimit(host,port,ULTRAPEER,KEEP_ALIVE - ConnectionManager.DESIRED_OLD_CONNECTIONS,REJECT_503);
  testPong(c,false);
}
Program: 4919
Project: 4919
Buggy source:
public static void main(String args[]){
  String host="String_Node_Str";
  int port=6346;
  System.out.println("String_Node_Str" + "String_Node_Str");
  SettingsManager settings=SettingsManager.instance();
  settings.setPort(6346);
  settings.setDirectories(new File[0]);
  settings.setUseQuickConnect(false);
  settings.setQuickConnectHosts(new String[0]);
  settings.setConnectOnStartup(false);
  settings.setEverSupernodeCapable(true);
  settings.setDisableSupernodeMode(false);
  settings.setForceSupernodeMode(false);
  settings.setMaxShieldedClientConnections(LEAF_CONNECTIONS);
  settings.setKeepAlive(KEEP_ALIVE);
  ActivityCallback callback=new ActivityCallbackStub();
  FileManager files=new FileManagerStub();
  TestMessageRouter router=new TestMessageRouter(callback,files);
  RouterService rs=new RouterService(callback,router,files,new DummyAuthenticator());
  rs.initialize();
  rs.clearHostCatcher();
  try {
    rs.setKeepAlive(6);
  }
 catch (  BadConnectionSettingException e) {
    e.printStackTrace();
    Assert.that(false);
  }
  System.out.println("String_Node_Str");
  testGuidanceI(rs);
  cleanup(rs);
  testGuidanceII(rs);
  cleanup(rs);
  testGuidanceIII(rs);
  cleanup(rs);
  testFetchI(rs,router);
  cleanup(rs);
  testFetchII(rs,router);
  cleanup(rs);
  testAcceptI(rs,router,host,port);
  cleanup(rs);
  testAcceptII(rs,router,host,port);
  cleanup(rs);
  testAcceptIII(rs,router,host,port);
}

Fixed version (ground truth):
public static void main(String args[]){
  String host="String_Node_Str";
  int port=6346;
  System.out.println("String_Node_Str" + "String_Node_Str");
  SettingsManager settings=SettingsManager.instance();
  settings.setPort(6346);
  settings.setDirectories(new File[0]);
  settings.setUseQuickConnect(false);
  settings.setQuickConnectHosts(new String[0]);
  settings.setConnectOnStartup(false);
  settings.setEverSupernodeCapable(true);
  settings.setDisableSupernodeMode(false);
  settings.setForceSupernodeMode(false);
  settings.setMaxShieldedClientConnections(LEAF_CONNECTIONS);
  settings.setKeepAlive(KEEP_ALIVE);
  ActivityCallback callback=new ActivityCallbackStub();
  FileManager files=new FileManagerStub();
  TestMessageRouter router=new TestMessageRouter(callback,files);
  TestRouterService rs=new TestRouterService(callback,router,files,new DummyAuthenticator());
  rs.initialize();
  rs.clearHostCatcher();
  try {
    rs.setKeepAlive(6);
  }
 catch (  BadConnectionSettingException e) {
    e.printStackTrace();
    Assert.that(false);
  }
  System.out.println("String_Node_Str");
  testGuidanceI(rs);
  cleanup(rs);
  testGuidanceII(rs);
  cleanup(rs);
  testGuidanceIII(rs);
  cleanup(rs);
  testFetchI(rs,router);
  cleanup(rs);
  testFetchII(rs,router);
  cleanup(rs);
  testAcceptI(rs,router,host,port);
  cleanup(rs);
  testAcceptII(rs,router,host,port);
  cleanup(rs);
  testAcceptIII(rs,router,host,port);
}
Program: 4920
Project: 4920
Buggy source:
private static void testAcceptII(RouterService rs,TestMessageRouter router,String host,int port){
  System.out.println("String_Node_Str");
  for (int i=0; i < 100; i++)   router.addHost("String_Node_Str" + i,6340,true);
  Connection c=testLimit(host,port,ULTRAPEER,KEEP_ALIVE,REJECT_SILENT);
  Assert.that(ConnectionHandshakeHeaders.isFalse(c.getProperty(ConnectionHandshakeHeaders.X_SUPERNODE_NEEDED)));
  testPong(c,true);
  testLimit(host,port,OLD_06,0,REJECT_503);
  testPong(c,true);
  testLimit(host,port,OLD_04,0,REJECT_SILENT);
  testPong(c,true);
  c=testLimit(host,port,LEAF,LEAF_CONNECTIONS,REJECT_503);
  testPong(c,false);
}

Fixed version (ground truth):
private static void testAcceptII(TestRouterService rs,TestMessageRouter router,String host,int port){
  System.out.println("String_Node_Str");
  for (int i=0; i < 100; i++)   router.addHost("String_Node_Str" + i,6340,true);
  Assert.that(!rs.getConnectionManager().isConnected(new Endpoint("String_Node_Str",17)));
  Connection c=testLimit(host,port,ULTRAPEER,KEEP_ALIVE,REJECT_SILENT);
  Assert.that(rs.getConnectionManager().isConnected(new Endpoint("String_Node_Str",17)));
  Assert.that(ConnectionHandshakeHeaders.isFalse(c.getProperty(ConnectionHandshakeHeaders.X_SUPERNODE_NEEDED)));
  testPong(c,true);
  testLimit(host,port,OLD_06,0,REJECT_503);
  testPong(c,true);
  testLimit(host,port,OLD_04,0,REJECT_SILENT);
  testPong(c,true);
  c=testLimit(host,port,LEAF,LEAF_CONNECTIONS,REJECT_503);
  testPong(c,false);
}
Program: 4921
Project: 4921
Buggy source:
public static void main(String args[]){
  String host="String_Node_Str";
  int port=6346;
  System.out.println("String_Node_Str" + "String_Node_Str");
  SettingsManager settings=SettingsManager.instance();
  settings.setPort(6346);
  settings.setDirectories(new File[0]);
  settings.setUseQuickConnect(false);
  settings.setQuickConnectHosts(new String[0]);
  settings.setConnectOnStartup(false);
  settings.setEverSupernodeCapable(true);
  settings.setDisableSupernodeMode(false);
  settings.setMaxShieldedClientConnections(LEAF_CONNECTIONS);
  ActivityCallback callback=new ActivityCallbackStub();
  FileManager files=new FileManagerStub();
  TestMessageRouter router=new TestMessageRouter(callback,files);
  RouterService rs=new RouterService(callback,router,files,new DummyAuthenticator());
  rs.initialize();
  rs.clearHostCatcher();
  try {
    rs.setKeepAlive(6);
  }
 catch (  BadConnectionSettingException e) {
    e.printStackTrace();
    Assert.that(false);
  }
  testFetchI(rs,router);
  cleanup(rs);
  testFetchII(rs,router);
  cleanup(rs);
  testAcceptI(rs,router,host,port);
  cleanup(rs);
  testAcceptII(rs,router,host,port);
  cleanup(rs);
  testAcceptIII(rs,router,host,port);
}

Fixed version (ground truth):
public static void main(String args[]){
  String host="String_Node_Str";
  int port=6346;
  System.out.println("String_Node_Str" + "String_Node_Str");
  SettingsManager settings=SettingsManager.instance();
  settings.setPort(6346);
  settings.setDirectories(new File[0]);
  settings.setUseQuickConnect(false);
  settings.setQuickConnectHosts(new String[0]);
  settings.setConnectOnStartup(false);
  settings.setEverSupernodeCapable(true);
  settings.setDisableSupernodeMode(false);
  settings.setMaxShieldedClientConnections(LEAF_CONNECTIONS);
  settings.setKeepAlive(KEEP_ALIVE);
  ActivityCallback callback=new ActivityCallbackStub();
  FileManager files=new FileManagerStub();
  TestMessageRouter router=new TestMessageRouter(callback,files);
  RouterService rs=new RouterService(callback,router,files,new DummyAuthenticator());
  rs.initialize();
  rs.clearHostCatcher();
  try {
    rs.setKeepAlive(6);
  }
 catch (  BadConnectionSettingException e) {
    e.printStackTrace();
    Assert.that(false);
  }
  testFetchI(rs,router);
  cleanup(rs);
  testFetchII(rs,router);
  cleanup(rs);
  testAcceptI(rs,router,host,port);
  cleanup(rs);
  testAcceptII(rs,router,host,port);
  cleanup(rs);
  testAcceptIII(rs,router,host,port);
}
Program: 4923
Project: 4923
Buggy source:
protected HandshakeResponse respondUnauthenticated(HandshakeResponse response,boolean outgoing) throws IOException {
  if (!outgoing) {
    Properties ret=new SupernodeProperties(_router,getRemoteIP());
    ret.put(ConnectionHandshakeHeaders.X_SUPERNODE_NEEDED,(new Boolean(_manager.supernodeNeeded())).toString());
    ret.put(ConnectionHandshakeHeaders.X_MY_ADDRESS,_manager.getSelfAddress().getHostname() + "String_Node_Str" + _manager.getSelfAddress().getPort());
    addHostAddresses(ret,_manager);
    Properties props=response.getHeaders();
    String isUltrapeer=props.getProperty(ConnectionHandshakeHeaders.X_SUPERNODE);
    if ((isUltrapeer == null && !_manager.hasAvailableIncoming(false,false)) || (!_manager.hasAvailableIncoming(true,true) && !_manager.hasAvailableIncoming(true,false))) {
      return new HandshakeResponse(HandshakeResponse.SLOTS_FULL,HandshakeResponse.SLOTS_FULL_MESSAGE,ret);
    }
 else {
      return new HandshakeResponse(ret);
    }
  }
 else {
    Properties ret=new Properties();
    String neededS=response.getHeaders().getProperty(ConnectionHandshakeHeaders.X_SUPERNODE_NEEDED);
    if (neededS != null && !Boolean.valueOf(neededS).booleanValue() && _manager.allowClientMode()) {
      ret.put(ConnectionHandshakeHeaders.X_SUPERNODE,"String_Node_Str");
    }
    return new HandshakeResponse(ret);
  }
}

Fixed version (ground truth):
protected HandshakeResponse respondUnauthenticated(HandshakeResponse response,boolean outgoing) throws IOException {
  if (!outgoing) {
    Properties ret=new SupernodeProperties(_router,getRemoteIP());
    ret.put(ConnectionHandshakeHeaders.X_SUPERNODE_NEEDED,(new Boolean(_manager.supernodeNeeded())).toString());
    ret.put(ConnectionHandshakeHeaders.X_MY_ADDRESS,_manager.getSelfAddress().getHostname() + "String_Node_Str" + _manager.getSelfAddress().getPort());
    addHostAddresses(ret,_manager);
    Properties props=response.getHeaders();
    String isUltrapeer=props.getProperty(ConnectionHandshakeHeaders.X_SUPERNODE);
    if (reject(isUltrapeer)) {
      return new HandshakeResponse(HandshakeResponse.SLOTS_FULL,HandshakeResponse.SLOTS_FULL_MESSAGE,ret);
    }
 else {
      return new HandshakeResponse(ret);
    }
  }
 else {
    Properties ret=new Properties();
    String neededS=response.getHeaders().getProperty(ConnectionHandshakeHeaders.X_SUPERNODE_NEEDED);
    if (neededS != null && !Boolean.valueOf(neededS).booleanValue() && _manager.allowClientMode()) {
      ret.put(ConnectionHandshakeHeaders.X_SUPERNODE,"String_Node_Str");
    }
    return new HandshakeResponse(ret);
  }
}
Program: 4924
Project: 4924
Buggy source:
/** 
 * Sees how many connections we can make of the given type, returning the last successful one, or null if none.
 */
private static Connection testLimit(String host,int port,int type){
  String description=null;
  if (type == OLD)   description="String_Node_Str";
 else   if (type == LEAF)   description="String_Node_Str";
 else   if (type == ULTRAPEER)   description="String_Node_Str";
 else   Assert.that(false,"String_Node_Str" + type);
  Connection ret=null;
  int i=0;
  while (i < MAX_CONNECTIONS) {
    Connection tmp=connect(host,port,type);
    if (tmp == null)     break;
    ret=tmp;
    buffer.add(ret);
    i++;
  }
  Assert.that(i < MAX_CONNECTIONS,"String_Node_Str" + description + "String_Node_Str");
  System.out.println("String_Node_Str" + i + "String_Node_Str"+ description+ "String_Node_Str");
  return ret;
}

Fixed version (ground truth):
/** 
 * Checks that HOST:PORT will accept LIMIT connections of the given type, returning the last successful one, or null if none.
 * @param host the host to connect to
 * @param port the port to conenct to
 * @param type the type of connection to establish: LEAF, OLD_04, OLD_06,or ULTRAPEER
 * @param limit the expected number of connections
 * @param rejectType what sort of rejection to expect when over the limit:REJECT_503 (during handshaking) or REJECT_SILENT (during messaging)
 */
private static Connection testLimit(String host,int port,int type,int limit,int rejectType){
  String description=null;
  if (type == OLD_04)   description="String_Node_Str";
 else   if (type == OLD_06)   description="String_Node_Str";
 else   if (type == LEAF)   description="String_Node_Str";
 else   if (type == ULTRAPEER)   description="String_Node_Str";
 else   Assert.that(false,"String_Node_Str" + type);
  System.out.println("String_Node_Str" + limit + "String_Node_Str"+ description+ "String_Node_Str");
  Connection ret=null;
  for (int i=0; i < limit; i++) {
    try {
      ret=connect(host,port,type);
    }
 catch (    IOException e) {
      Assert.that(false,"String_Node_Str" + i + "String_Node_Str");
    }
    buffer.add(ret);
  }
  try {
    Connection tmp=connect(host,port,type);
    Assert.that(false,"String_Node_Str");
  }
 catch (  NoGnutellaOkException e) {
    Assert.that(rejectType == REJECT_503 && e.getCode() == HandshakeResponse.SLOTS_FULL,"String_Node_Str" + e.getCode());
  }
catch (  IOException e) {
    Assert.that(rejectType == REJECT_SILENT,"String_Node_Str" + e);
  }
  return ret;
}
Program: 4925
Project: 4925
Buggy source:
public void connectionInitializing(Connection c){
}

Fixed version (ground truth):
public void connectionInitializing(Connection c){
  if (AcceptLimitTest.DEBUG)   System.out.println("String_Node_Str" + str(c));
}
Program: 4926
Project: 4926
Buggy source:
public void connectionInitialized(Connection c){
  System.out.println("String_Node_Str" + str(c));
}

Fixed version (ground truth):
public void connectionInitialized(Connection c){
}
Program: 4927
Project: 4927
Buggy source:
public static void main(String args[]){
  String host="String_Node_Str";
  int port=6346;
  SettingsManager settings=SettingsManager.instance();
  settings.setPort(6346);
  settings.setQuickConnectHosts(new String[0]);
  settings.setConnectOnStartup(true);
  settings.setConnectOnStartup(false);
  settings.setEverSupernodeCapable(true);
  settings.setDisableSupernodeMode(true);
  settings.setMaxShieldedClientConnections(25);
  RouterService rs=new RouterService(new DebugActivityCallback(),new MessageRouterStub(),new FileManagerStub(),new DummyAuthenticator());
  rs.initialize();
  rs.clearHostCatcher();
  try {
    rs.setKeepAlive(6);
  }
 catch (  BadConnectionSettingException e) {
    Assert.that(false);
  }
  Connection c=testLimit(host,port,LEAF);
  testPong(c,true);
  testLimit(host,port,OLD);
  testPong(c,true);
  testLimit(host,port,ULTRAPEER);
  testPong(c,false);
}

Fixed version (ground truth):
public static void main(String args[]){
  String host="String_Node_Str";
  int port=6346;
  System.out.println("String_Node_Str");
  SettingsManager settings=SettingsManager.instance();
  settings.setPort(6346);
  settings.setQuickConnectHosts(new String[0]);
  settings.setConnectOnStartup(false);
  settings.setEverSupernodeCapable(true);
  settings.setDisableSupernodeMode(false);
  settings.setMaxShieldedClientConnections(LEAF_CONNECTIONS);
  ActivityCallback callback=new ActivityCallbackStub();
  FileManager files=new FileManagerStub();
  RouterService rs=new RouterService(callback,new MetaEnabledMessageRouter(callback,files),files,new DummyAuthenticator());
  rs.initialize();
  rs.clearHostCatcher();
  try {
    rs.setKeepAlive(6);
  }
 catch (  BadConnectionSettingException e) {
    Assert.that(false);
  }
  Connection c=null;
  System.out.println("String_Node_Str");
  c=testLimit(host,port,LEAF,LEAF_CONNECTIONS,REJECT_503);
  testPong(c,true);
  testLimit(host,port,OLD_06,KEEP_ALIVE,REJECT_503);
  testPong(c,true);
  testLimit(host,port,ULTRAPEER,KEEP_ALIVE - ConnectionManager.DESIRED_OLD_CONNECTIONS,REJECT_503);
  testPong(c,false);
  cleanup(rs);
  System.out.println("String_Node_Str");
  c=testLimit(host,port,ULTRAPEER,KEEP_ALIVE,REJECT_SILENT);
  testPong(c,true);
  testLimit(host,port,OLD_06,0,REJECT_503);
  testPong(c,true);
  testLimit(host,port,OLD_04,0,REJECT_SILENT);
  testPong(c,true);
  c=testLimit(host,port,LEAF,LEAF_CONNECTIONS,REJECT_503);
  testPong(c,false);
}
Program: 4928
Project: 4928
Buggy source:
public void connectionClosed(Connection c){
  System.out.println("String_Node_Str" + str(c));
}

Fixed version (ground truth):
public void connectionClosed(Connection c){
  if (AcceptLimitTest.DEBUG)   System.out.println("String_Node_Str" + str(c));
}
Program: 4929
Project: 4929
Buggy source:
/** 
 * Returns a connection of the given type to host:port,  or null if it failed.
 * @param type one of t
 */
private static Connection connect(String host,int port,int type){
  Connection ret=null;
  if (type == OLD)   ret=new Connection(host,port);
 else   if (type == LEAF)   ret=new Connection(host,port,new LeafProperties(),new EmptyResponder(),false);
 else   if (type == ULTRAPEER)   ret=new Connection(host,port,new UltrapeerProperties(),new EmptyResponder(),false);
 else   Assert.that(false,"String_Node_Str" + type);
  try {
    ret.initialize();
    ret.send(new PingRequest((byte)7));
    ret.flush();
    Message m=ret.receive();
    return ret;
  }
 catch (  IOException e) {
    return null;
  }
catch (  BadPacketException e) {
    return null;
  }
}

Fixed version (ground truth):
/** 
 * Returns a connection of the given type to host:port,  or null if it failed.
 * @param type one of t
 */
private static Connection connect(String host,int port,int type) throws IOException {
  Connection ret=null;
  if (type == OLD_04)   ret=new Connection(host,port);
 else   if (type == OLD_06)   ret=new Connection(host,port,new Properties(),new EmptyResponder(),false);
 else   if (type == LEAF)   ret=new Connection(host,port,new LeafProperties(),new EmptyResponder(),false);
 else   if (type == ULTRAPEER)   ret=new Connection(host,port,new UltrapeerProperties(),new EmptyResponder(),false);
 else   Assert.that(false,"String_Node_Str" + type);
  ret.initialize();
  try {
    ret.send(new PingRequest((byte)7));
    ret.flush();
    Message m=ret.receive();
  }
 catch (  BadPacketException e) {
    throw new IOException("String_Node_Str");
  }
  return ret;
}
Program: 4930
Project: 4930
Buggy source:
/** 
 * @param a human readable description of this media type,i.e., "Hypertext Documents"
 * @param extensions a list of all file extensions of thistype.  Must be all lowercase.  If null, this matches any file.
 */
public MediaType(String description,String[] extensions){
  this.description=description;
  this.extensions=extensions;
}

Fixed version (ground truth):
/** 
 * @param schema a MIME compliant non-localizable identifier,that matches file categories (and XSD schema names).
 * @param descriptionKey a media identifier that can be usedto retreive a localizable descriptive text.
 * @param extensions a list of all file extensions of thistype.  Must be all lowercase.  If null, this matches any file.
 */
public MediaType(String schema,String description,String[] extensions){
  this.schema=schema;
  this.description=description;
  this.extensions=extensions;
}
Program: 4931
Project: 4931
Buggy source:
/** 
 * Returns this' human-readable description
 */
public String toString(){
  return description;
}

Fixed version (ground truth):
/** 
 * Returns this' media-type (a MIME content-type category) (previously returned a description key)
 */
public String toString(){
  return schema;
}
Program: 4933
Project: 4933
Buggy source:
public static MediaType[] getDefaultMediaTypes(){
  if (allMediaTypes == null)   allMediaTypes=getTypes();
  return allMediaTypes;
}

Fixed version (ground truth):
public static final MediaType[] getDefaultMediaTypes(){
  if (allMediaTypes == null)   allMediaTypes=getTypes();
  return allMediaTypes;
}
Program: 4934
Project: 4934
Buggy source:
/** 
 * Reads the downloaders serialized in DOWNLOAD_SNAPSHOT_FILE and adds them to this, queued.  The queued downloads will restart immediately if slots are available.  Returns false iff the file could not be read for any reason.  THIS METHOD SHOULD BE CALLED BEFORE ANY GUI ACTION. 
 */
public synchronized boolean readSnapshot(){
  List buf=null;
  try {
    ObjectInputStream in=new ObjectInputStream(new FileInputStream(SettingsManager.instance().getDownloadSnapshotFile()));
    buf=(List)in.readObject();
    incompleteFileManager=(IncompleteFileManager)in.readObject();
  }
 catch (  IOException e) {
    return false;
  }
catch (  ClassCastException e) {
    return false;
  }
catch (  ClassNotFoundException e) {
    return false;
  }
  if (incompleteFileManager.purge())   writeSnapshot();
  try {
    for (Iterator iter=buf.iterator(); iter.hasNext(); ) {
      ManagedDownloader downloader=(ManagedDownloader)iter.next();
      waiting.add(downloader);
      downloader.initialize(this,this.fileManager);
      callback.addDownload(downloader);
    }
    return true;
  }
 catch (  ClassCastException e) {
    return false;
  }
}

Fixed version (ground truth):
/** 
 * Reads the downloaders serialized in DOWNLOAD_SNAPSHOT_FILE and adds them to this, queued.  The queued downloads will restart immediately if slots are available.  Returns false iff the file could not be read for any reason.  THIS METHOD SHOULD BE CALLED BEFORE ANY GUI ACTION. 
 */
synchronized boolean readSnapshot(){
  List buf=null;
  try {
    ObjectInputStream in=new ObjectInputStream(new FileInputStream(SettingsManager.instance().getDownloadSnapshotFile()));
    buf=(List)in.readObject();
    incompleteFileManager=(IncompleteFileManager)in.readObject();
  }
 catch (  IOException e) {
    return false;
  }
catch (  ClassCastException e) {
    return false;
  }
catch (  ClassNotFoundException e) {
    return false;
  }
  if (incompleteFileManager.purge())   writeSnapshot();
  try {
    for (Iterator iter=buf.iterator(); iter.hasNext(); ) {
      ManagedDownloader downloader=(ManagedDownloader)iter.next();
      waiting.add(downloader);
      downloader.initialize(this,this.fileManager);
      callback.addDownload(downloader);
    }
    return true;
  }
 catch (  ClassCastException e) {
    return false;
  }
}
Program: 4935
Project: 4935
Buggy source:
/** 
 * Writes a snapshot of all downloaders in this and all incomplete files to the file named DOWNLOAD_SNAPSHOT_FILE.  It is safe to call this method at any time for checkpointing purposes.  Returns true iff the file was successfully written. 
 */
public synchronized boolean writeSnapshot(){
  List buf=new ArrayList();
  buf.addAll(active);
  buf.addAll(waiting);
  for (Iterator iter=buf.iterator(); iter.hasNext(); ) {
    ManagedDownloader downloader=(ManagedDownloader)iter.next();
    downloader.updateIncompleteFileManager();
  }
  try {
    ObjectOutputStream out=new ObjectOutputStream(new FileOutputStream(SettingsManager.instance().getDownloadSnapshotFile()));
    out.writeObject(buf);
synchronized (incompleteFileManager) {
      out.writeObject(incompleteFileManager);
    }
    out.flush();
    out.close();
    return true;
  }
 catch (  IOException e) {
    return false;
  }
}

Fixed version (ground truth):
/** 
 * Writes a snapshot of all downloaders in this and all incomplete files to the file named DOWNLOAD_SNAPSHOT_FILE.  It is safe to call this method at any time for checkpointing purposes.  Returns true iff the file was successfully written. 
 */
synchronized boolean writeSnapshot(){
  List buf=new ArrayList();
  buf.addAll(active);
  buf.addAll(waiting);
  for (Iterator iter=buf.iterator(); iter.hasNext(); ) {
    ManagedDownloader downloader=(ManagedDownloader)iter.next();
    downloader.updateIncompleteFileManager();
  }
  try {
    ObjectOutputStream out=new ObjectOutputStream(new FileOutputStream(SettingsManager.instance().getDownloadSnapshotFile()));
    out.writeObject(buf);
synchronized (incompleteFileManager) {
      out.writeObject(incompleteFileManager);
    }
    out.flush();
    out.close();
    return true;
  }
 catch (  IOException e) {
    return false;
  }
}
Program: 4936
Project: 4936
Buggy source:
/** 
 * Initializes this manager. <b>This method must be called before any other methods are used.</b> 
 * @param callback the UI callback to notify of download changes
 * @param router the message router to use for sending push requests
 * @param acceptor used to get my IP address and port for pushes
 * @param fileManager used to check if files exist
 * @param backend provides the schedule(..) method for checkpointing downloads.dat
 */
public void initialize(ActivityCallback callback,MessageRouter router,Acceptor acceptor,FileManager fileManager,RouterService backend){
  this.callback=callback;
  this.router=router;
  this.acceptor=acceptor;
  this.fileManager=fileManager;
  Runnable checkpointer=new Runnable(){
    public void run(){
      if (downloadsInProgress() > 0)       writeSnapshot();
    }
  }
;
  backend.schedule(checkpointer,0,SNAPSHOT_CHECKPOINT_TIME);
}

Fixed version (ground truth):
/** 
 * Initializes this manager. <b>This method must be called before any other methods are used.</b> 
 * @param callback the UI callback to notify of download changes
 * @param router the message router to use for sending push requests
 * @param acceptor used to get my IP address and port for pushes
 * @param fileManager used to check if files exist
 */
public void initialize(ActivityCallback callback,MessageRouter router,Acceptor acceptor,FileManager fileManager){
  this.callback=callback;
  this.router=router;
  this.acceptor=acceptor;
  this.fileManager=fileManager;
}
Program: 4937
Project: 4937
Buggy source:
/** 
 * Kicks off expensive backend tasks (like file loading) that should only be done after GUI is loaded. 
 */
public void postGuiInit(){
  fileManager.initialize(callback);
  downloader.readSnapshot();
}

Fixed version (ground truth):
/** 
 * Kicks off expensive backend tasks (like file loading) that should only be done after GUI is loaded. 
 */
public void postGuiInit(){
  fileManager.initialize(callback);
  downloader.postGuiInit(this);
}
Program: 4938
Project: 4938
Buggy source:
/** 
 * Initializes the key backend components.  Some tasks are postponed until postGuiInit().
 */
public void initialize(){
  SettingsManager settings=SettingsManager.instance();
  int port=settings.getPort();
  this.acceptor=new Acceptor(port,callback);
  this.manager=createConnectionManager();
  this.catcher=createHostCatcher();
  this.downloader=new DownloadManager();
  this.uploadManager=new UploadManager();
  this.chatManager=ChatManager.instance();
  this.catcher.initialize(acceptor,manager,SettingsManager.instance().getHostList());
  this.router.initialize(acceptor,manager,catcher,uploadManager);
  this.manager.initialize(router,catcher);
  this.uploadManager.initialize(callback,router,acceptor,fileManager);
  this.acceptor.initialize(manager,router,downloader,uploadManager);
  this.chatManager.setActivityCallback(callback);
  this.downloader.initialize(callback,router,acceptor,fileManager,this);
  SupernodeAssigner sa=new SupernodeAssigner(uploadManager,downloader,manager);
  sa.start(this);
  if (settings.getConnectOnStartup()) {
    int outgoing=settings.getKeepAlive();
    if (outgoing > 0)     connect();
  }
}

Fixed version (ground truth):
/** 
 * Initializes the key backend components.  Some tasks are postponed until postGuiInit().
 */
public void initialize(){
  SettingsManager settings=SettingsManager.instance();
  int port=settings.getPort();
  this.acceptor=new Acceptor(port,callback);
  this.manager=createConnectionManager();
  this.catcher=createHostCatcher();
  this.downloader=new DownloadManager();
  this.uploadManager=new UploadManager();
  this.chatManager=ChatManager.instance();
  this.catcher.initialize(acceptor,manager,SettingsManager.instance().getHostList());
  this.router.initialize(acceptor,manager,catcher,uploadManager);
  this.manager.initialize(router,catcher);
  this.uploadManager.initialize(callback,router,acceptor,fileManager);
  this.acceptor.initialize(manager,router,downloader,uploadManager);
  this.chatManager.setActivityCallback(callback);
  this.downloader.initialize(callback,router,acceptor,fileManager);
  SupernodeAssigner sa=new SupernodeAssigner(uploadManager,downloader,manager);
  sa.start(this);
  if (settings.getConnectOnStartup()) {
    int outgoing=settings.getKeepAlive();
    if (outgoing > 0)     connect();
  }
}
Program: 4939
Project: 4939
Buggy source:
/** 
 * Returns true iff file is "too old". 
 */
private static final boolean isOld(File file){
  long lastModified=file.lastModified();
  int days=SettingsManager.instance().getIncompletePurgeTime();
  long purgeTime=System.currentTimeMillis() - days * 24 * 60* 60* 1000;
  return lastModified < purgeTime;
}

Fixed version (ground truth):
/** 
 * Returns true iff file is "too old". 
 */
private static final boolean isOld(File file){
  long lastModified=file.lastModified();
  long days=SettingsManager.instance().getIncompletePurgeTime();
  long purgeTime=System.currentTimeMillis() - days * 24l * 60l* 60l* 1000l;
  return lastModified < purgeTime;
}
Program: 4941
Project: 4941
Buggy source:
public void replaceDoc(Object hash,LimeXMLDocument newDoc){
synchronized (mainMapLock) {
    mainMap.put(hash,newDoc);
  }
  replyDocs=null;
}

Fixed version (ground truth):
/** 
 * @return the older document, which is being replaced. Can be null.
 */
public LimeXMLDocument replaceDoc(Object hash,LimeXMLDocument newDoc){
  LimeXMLDocument oldDoc=null;
synchronized (mainMapLock) {
    oldDoc=(LimeXMLDocument)mainMap.get(hash);
    mainMap.put(hash,newDoc);
  }
  replyDocs=null;
  return oldDoc;
}
Program: 4942
Project: 4942
Buggy source:
public boolean mp3ToDisk(String mp3FileName){
  boolean mp3=LimeXMLUtils.isMP3File(mp3FileName);
  boolean wrote=false;
  boolean wrote2=false;
  toDisk(mp3FileName);
  if (this.editor != null) {
    wrote2=this.editor.writeID3DataToDisk(mp3FileName);
    File file=new File(mp3FileName);
    String newHash=null;
    try {
      newHash=new String(LimeXMLUtils.hashFile(file));
    }
 catch (    Exception e) {
      return false;
    }
synchronized (mainMapLock) {
      Object mainValue=mainMap.remove(changedHash);
      mainMap.put(newHash,mainValue);
    }
    metaFileManager.writeToMap(file,newHash,mp3);
    metaFileManager.handleChangedHash(changedHash,newHash,this);
    Object outValue=outMap.remove(changedHash);
    outMap.put(newHash,outValue);
  }
 else   wrote2=true;
  wrote=write();
  this.outMap=null;
  this.changedHash=null;
  this.editor=null;
  return (wrote && wrote2);
}

Fixed version (ground truth):
public int mp3ToDisk(String mp3FileName){
  boolean mp3=LimeXMLUtils.isMP3File(mp3FileName);
  boolean wrote=false;
  int mp3WriteState=-1;
  toDisk(mp3FileName);
  if (this.editor != null) {
    mp3WriteState=this.editor.writeID3DataToDisk(mp3FileName);
    if (mp3WriteState != NORMAL)     return mp3WriteState;
    File file=new File(mp3FileName);
    String newHash=null;
    try {
      newHash=new String(LimeXMLUtils.hashFile(file));
    }
 catch (    Exception e) {
      return HASH_FAILED;
    }
synchronized (mainMapLock) {
      Object mainValue=mainMap.remove(changedHash);
      mainMap.put(newHash,mainValue);
    }
    metaFileManager.writeToMap(file,newHash,mp3);
    metaFileManager.handleChangedHash(changedHash,newHash,this);
    Object outValue=outMap.remove(changedHash);
    outMap.put(newHash,outValue);
  }
  wrote=write();
  this.outMap=null;
  this.changedHash=null;
  this.editor=null;
  if (!wrote) {
    System.out.println("String_Node_Str");
    return RW_ERROR;
  }
  return mp3WriteState;
}
Program: 4943
Project: 4943
Buggy source:
/** 
 * Returns the directory where all user settings should be stored.  This is where all application data should be stored.  If the directory does does not already exist, this attempts to create the directory, although this is not guaranteed to succeed.
 * @return the <tt>File</tt> instance denoting the user's home directory for the application, or <tt>null</tt> if that directory  does not exist
 */
public static File getUserSettingsDir(){
  File settingsDir=null;
  if (CommonUtils.isWindows()) {
    settingsDir=CommonUtils.getCurrentDirectory();
  }
 else   if (CommonUtils.isMacOSX()) {
    File userPrefsDir;
    try {
      short userDomainCode=-32763;
      userPrefsDir=MRJFileUtils.findFolder(userDomainCode,new MRJOSType("String_Node_Str"));
      settingsDir=new File(userPrefsDir,"String_Node_Str");
    }
 catch (    FileNotFoundException e) {
    }
  }
 else {
    settingsDir=new File(CommonUtils.getUserHomeDir(),"String_Node_Str");
  }
  if (settingsDir == null) {
    settingsDir=new File(CommonUtils.getUserHomeDir(),"String_Node_Str");
  }
  if (!settingsDir.isDirectory()) {
    settingsDir.mkdirs();
  }
  return settingsDir;
}

Fixed version (ground truth):
/** 
 * Returns the directory where all user settings should be stored.  This is where all application data should be stored.  If the directory does does not already exist, this attempts to create the directory, although this is not guaranteed to succeed.
 * @return the <tt>File</tt> instance denoting the user's home directory for the application, or <tt>null</tt> if that directory  does not exist
 */
public static File getUserSettingsDir(){
  File settingsDir=null;
  if (CommonUtils.isWindows()) {
    settingsDir=CommonUtils.getCurrentDirectory();
  }
 else   if (CommonUtils.isMacOSX()) {
    File userPrefsDir;
    try {
      short userDomainCode=-32763;
      userPrefsDir=MRJFileUtils.findFolder(userDomainCode,new MRJOSType("String_Node_Str"));
      settingsDir=new File(userPrefsDir,"String_Node_Str");
    }
 catch (    FileNotFoundException e) {
    }
catch (    NoSuchMethodError e) {
      settingsDir=CommonUtils.getCurrentDirectory();
    }
  }
 else {
    settingsDir=new File(CommonUtils.getUserHomeDir(),"String_Node_Str");
  }
  if (settingsDir == null) {
    settingsDir=new File(CommonUtils.getUserHomeDir(),"String_Node_Str");
  }
  if (!settingsDir.isDirectory()) {
    settingsDir.mkdirs();
  }
  return settingsDir;
}
Program: 4944
Project: 4944
Buggy source:
/** 
 * See note on serialization at top of file  <p> Note that we are serializing a new BandwidthImpl to the stream.  This is for compatibility reasons, so the new version of the code  will run with an older download.dat file.     
 */
private synchronized void writeObject(ObjectOutputStream stream) throws IOException {
  stream.writeObject(allFiles);
synchronized (incompleteFileManager) {
    stream.writeObject(incompleteFileManager);
  }
  stream.writeObject(new BandwidthTrackerImpl());
}

Fixed version (ground truth):
/** 
 * See note on serialization at top of file  <p> Note that we are serializing a new BandwidthImpl to the stream.  This is for compatibility reasons, so the new version of the code  will run with an older download.dat file.     
 */
private synchronized void writeObject(ObjectOutputStream stream) throws IOException {
  stream.writeObject(allFiles);
synchronized (incompleteFileManager) {
    stream.writeObject(incompleteFileManager);
  }
  stream.writeObject(null);
}
Program: 4945
Project: 4945
Buggy source:
/** 
 * Waits for a timer task appropriate for execution.  Returns null if none is yet ready; call waitForTask again in this case.  
 * @exception InterruptedException this was interrupted while waiting
 */
private SimpleTimerTask waitForTask() throws InterruptedException {
synchronized (_queue) {
    if (_queue.isEmpty()) {
      _queue.wait();
      return null;
    }
 else {
      SimpleTimerTask task=(SimpleTimerTask)_queue.extractMax();
      long time=task.timeUntilExecution();
      if (time > 0) {
        _queue.wait(time);
        return null;
      }
 else {
        return task;
      }
    }
  }
}

Fixed version (ground truth):
/** 
 * Waits for and removes timer task appropriate for execution.  Returns null if none is yet ready; call waitForTask again in this case.
 * @exception InterruptedException this was interrupted while waiting
 */
private SimpleTimerTask waitForTask() throws InterruptedException {
synchronized (_queue) {
    if (_queue.isEmpty()) {
      _queue.wait();
      return null;
    }
 else {
      SimpleTimerTask task=(SimpleTimerTask)_queue.getMax();
      long time=task.timeUntilExecution();
      if (time > 0) {
        _queue.wait(time);
        return null;
      }
 else {
        SimpleTimerTask task2=(SimpleTimerTask)_queue.extractMax();
        Assert.that(task2 == task,"String_Node_Str");
        return task;
      }
    }
  }
}
Program: 4946
Project: 4946
Buggy source:
/** 
 * Schedules the given task for fixed-delay execution after the given delay, repeating every period.
 * @param task the task to run repeatedly
 * @param delay the initial delay, in milliseconds
 * @param period the delay between executions, in milliseconds
 * @exception IllegalStateException this is cancelled
 * @see java.util.Timer#schedule(java.util.TimerTask,long,long)
 */
public void schedule(Runnable task,long delay,long period) throws IllegalStateException {
  if (_isCancelled)   throw new IllegalStateException("String_Node_Str");
  long now=System.currentTimeMillis();
  SimpleTimerTask ttask=new SimpleTimerTask(task,period,now + delay);
synchronized (_queue) {
    Object discarded=_queue.insert(ttask);
    Assert.that(discarded == null,"String_Node_Str");
    _queue.notify();
  }
}

Fixed version (ground truth):
/** 
 * Schedules the given task for fixed-delay execution after the given delay, repeating every period.
 * @param task the task to run repeatedly
 * @param delay the initial delay, in milliseconds
 * @param period the delay between executions, in milliseconds
 * @exception IllegalStateException this is cancelled
 * @exception IllegalArgumentException delay or period negative
 * @see java.util.Timer#schedule(java.util.TimerTask,long,long)
 */
public void schedule(Runnable task,long delay,long period) throws IllegalStateException {
  if (_isCancelled)   throw new IllegalStateException("String_Node_Str");
  if (delay < 0)   throw new IllegalArgumentException("String_Node_Str" + delay);
  if (period < 0)   throw new IllegalArgumentException("String_Node_Str" + period);
  long now=System.currentTimeMillis();
  SimpleTimerTask ttask=new SimpleTimerTask(task,period,now + delay,_callback);
synchronized (_queue) {
    Object discarded=_queue.insert(ttask);
    Assert.that(discarded == null,"String_Node_Str");
    _queue.notify();
  }
}
Program: 4947
Project: 4947
Buggy source:
/** 
 * Returns the time in milliseconds to wait until this should be run. Returns a non-positive value if this should be run immediately.
 */
public long timeUntilExecution(){
  return System.currentTimeMillis() - _nextTime;
}

Fixed version (ground truth):
/** 
 * Returns the time in milliseconds to wait until this should be run. Returns a non-positive value if this should be run immediately.
 */
public long timeUntilExecution(){
  return _nextTime - System.currentTimeMillis();
}
Program: 4948
Project: 4948
Buggy source:
/** 
 * Calls _task.run(), then updates _nextTime.  Catches any exceptions while running task.  
 */
public void runAndReschedule(){
  try {
    _task.run();
  }
 catch (  Exception e) {
  }
  _nextTime=System.currentTimeMillis() + _period;
}

Fixed version (ground truth):
/** 
 * Calls _task.run(), then updates _nextTime.  Catches any exceptions while running task.  
 */
public void runAndReschedule(){
  try {
    _task.run();
  }
 catch (  Exception e) {
    if (_callback != null)     _callback.error(e);
  }
  _nextTime=System.currentTimeMillis() + _period;
}
Program: 4949
Project: 4949
Buggy source:
/** 
 * Creates a new active SimpleTimer.
 * @param isDaemon true if this' thread should be a daemon.
 */
public SimpleTimer(boolean isDaemon){
  _runner=new TimerRunnerThread(isDaemon);
  _runner.start();
}

Fixed version (ground truth):
/** 
 * Creates a new active SimpleTimer with a callback for internal errors.
 * @param isDaemon true if this' thread should be a daemon.
 * @param callback if non-null, calls callback.error(..) if any scheduledtasks throws an uncaught exception
 */
public SimpleTimer(boolean isDaemon,ActivityCallback callback){
  _runner=new TimerRunnerThread(isDaemon);
  _runner.start();
  _callback=callback;
}
Program: 4950
Project: 4950
Buggy source:
SimpleTimerTask(Runnable task,long period,long nextTime){
  this._task=task;
  this._period=period;
  this._nextTime=nextTime;
}

Fixed version (ground truth):
SimpleTimerTask(Runnable task,long period,long nextTime,ActivityCallback callback){
  this._task=task;
  this._period=period;
  this._nextTime=nextTime;
  this._callback=callback;
}
Program: 4951
Project: 4951
Buggy source:
/** 
 * While the connection is not closed, sends all data delay. 
 */
public void run(){
  while (isOpen()) {
    repOk();
    try {
      waitForQueued();
    }
 catch (    InterruptedException e) {
      System.err.println("String_Node_Str");
      System.err.println("String_Node_Str");
      return;
    }
    try {
      sendQueued();
    }
 catch (    IOException e) {
      _manager.remove(ManagedConnection.this);
    }
    repOk();
  }
}

Fixed version (ground truth):
/** 
 * While the connection is not closed, sends all data delay. 
 */
public void run(){
  while (true) {
    repOk();
    try {
      waitForQueued();
      sendQueued();
    }
 catch (    IOException e) {
      if (_manager != null)       _manager.remove(ManagedConnection.this);
      _runnerDied=true;
      return;
    }
    repOk();
  }
}
Program: 4952
Project: 4952
Buggy source:
/** 
 * Wait until the queue is (probably) non-empty. 
 */
private final void waitForQueued() throws InterruptedException {
  if (isInterrupted()) {
    throw new InterruptedException();
  }
synchronized (_outputQueueLock) {
    while (_queued == 0) {
      _outputQueueLock.wait();
    }
  }
}

Fixed version (ground truth):
/** 
 * Wait until the queue is (probably) non-empty or closed. 
 * @exception IOException this was closed while waiting
 */
private final void waitForQueued() throws IOException {
synchronized (_outputQueueLock) {
    while (isOpen() && _queued == 0) {
      try {
        _outputQueueLock.wait();
      }
 catch (      InterruptedException e) {
        Assert.that(false,"String_Node_Str");
      }
    }
  }
  if (!isOpen())   throw new IOException();
}
Program: 4953
Project: 4953
Buggy source:
/** 
 * Override of receive to do MessageRouter stats and to properly shut down the connection on IOException
 */
public Message receive(int timeout) throws IOException, BadPacketException, InterruptedIOException {
  Message m=null;
  try {
    m=super.receive(timeout);
    _bytesReceived+=m.getTotalLength();
  }
 catch (  IOException e) {
    _manager.remove(this);
    throw e;
  }
  _numMessagesReceived++;
  _router.countMessage();
  return m;
}

Fixed version (ground truth):
/** 
 * Override of receive to do MessageRouter stats and to properly shut down the connection on IOException
 */
public Message receive(int timeout) throws IOException, BadPacketException, InterruptedIOException {
  Message m=null;
  try {
    m=super.receive(timeout);
    _bytesReceived+=m.getTotalLength();
  }
 catch (  IOException e) {
    if (_manager != null)     _manager.remove(this);
    throw e;
  }
  _numMessagesReceived++;
  _router.countMessage();
  return m;
}
Program: 4954
Project: 4954
Buggy source:
public void initialize() throws IOException, NoGnutellaOkException, BadHandshakeException {
  super.initialize();
  _outputRunnerThread=new OutputRunner();
}

Fixed version (ground truth):
public void initialize() throws IOException, NoGnutellaOkException, BadHandshakeException {
  super.initialize();
  new OutputRunner();
}
Program: 4955
Project: 4955
Buggy source:
private static boolean download(String file,String header,String expResp) throws IOException {
  Socket s=new Socket(address,port);
  BufferedReader in=new BufferedReader(new InputStreamReader(s.getInputStream()));
  BufferedWriter out=new BufferedWriter(new OutputStreamWriter(s.getOutputStream()));
  String ret=downloadInternal(file,header,out,in);
  in.close();
  out.close();
  s.close();
  return ret.equals(expResp);
}

Fixed version (ground truth):
private static boolean download(String file,String header,String expResp,String expHeader) throws IOException {
  Socket s=new Socket(address,port);
  BufferedReader in=new BufferedReader(new InputStreamReader(s.getInputStream()));
  BufferedWriter out=new BufferedWriter(new OutputStreamWriter(s.getOutputStream()));
  String ret=downloadInternal(file,header,out,in,expHeader);
  in.close();
  out.close();
  s.close();
  return ret.equals(expResp);
}