Program: 178648
Project: 178648
Buggy source:
byte[] loadFile(PassthroughConnection ptc,int id,long requestedHash){
  Reference<byte[]> ref=cache.get(requestedHash);
  if (ref != null) {
    byte[] block=ref.get();
    if (block != null) {
      return block;
    }
  }
  if (cache.containsKey(requestedHash)) {
  }
  System.out.println("String_Node_Str" + id);
  File f=new File(cacheDir,"String_Node_Str" + id);
  FileInputStream fileIn;
  GZIPInputStream gzin;
  try {
    fileIn=new FileInputStream(f);
    gzin=new GZIPInputStream(fileIn);
  }
 catch (  IOException e) {
    return null;
  }
  DataInputStream in=new DataInputStream(gzin);
  byte[] requestedBlock=null;
  ConcurrentLinkedQueue<Long> sendQueue=ptc.connectionInfo.hashesToSend;
  ConcurrentHashMap<Long,Boolean> sentAlready=ptc.connectionInfo.hashesSent;
  boolean eof=false;
  while (!eof) {
    try {
      long hash=in.readLong();
      byte[] block=new byte[2048];
      in.readFully(block);
      if (hash == requestedHash) {
        requestedBlock=block;
      }
      cache.put(hash,new SoftReference<byte[]>(block));
      if (!sentAlready.containsKey(hash)) {
        sendQueue.add(hash);
      }
      hardLoop.add(block);
      int loopSize=hardLoopSize.incrementAndGet();
      while (loopSize > 32768) {
        hardLoop.poll();
        loopSize=hardLoopSize.decrementAndGet();
      }
    }
 catch (    EOFException eof1) {
      eof=true;
      continue;
    }
catch (    IOException ioe) {
      if (in != null) {
        try {
          in.close();
        }
 catch (        IOException ioe2) {
          return null;
        }
      }
      return null;
    }
  }
  return requestedBlock;
}

Fixed version (ground truth):
byte[] loadFile(PassthroughConnection ptc,int id,long requestedHash){
  Object fileLock=fileLocks.get(id);
  if (fileLock == null) {
    fileLock=new Object();
    Object oldLock=fileLocks.putIfAbsent(id,fileLock);
    if (oldLock != null) {
      fileLock=oldLock;
    }
  }
synchronized (fileLock) {
    ConcurrentHashMap<Long,Boolean> received=ptc.connectionInfo.hashesReceived;
    Reference<byte[]> ref=cache.get(requestedHash);
    if (ref != null && received.containsKey(requestedHash)) {
      byte[] block=ref.get();
      if (block != null) {
        return block;
      }
    }
    System.out.println("String_Node_Str" + id);
    File f=new File(cacheDir,"String_Node_Str" + id);
    FileInputStream fileIn;
    GZIPInputStream gzin;
    try {
      fileIn=new FileInputStream(f);
      gzin=new GZIPInputStream(fileIn);
    }
 catch (    IOException e) {
      return null;
    }
    DataInputStream in=new DataInputStream(gzin);
    byte[] requestedBlock=null;
    ConcurrentLinkedQueue<Long> sendQueue=ptc.connectionInfo.hashesToSend;
    ConcurrentHashMap<Long,Boolean> sentAlready=ptc.connectionInfo.hashesSent;
    boolean eof=false;
    while (!eof) {
      try {
        long hash=in.readLong();
        byte[] block=null;
        ref=cache.get(hash);
        if (ref != null) {
          block=ref.get();
        }
        if (block == null) {
          block=new byte[2048];
          in.readFully(block);
        }
 else {
          in.skip(2048);
        }
        if (hash == requestedHash) {
          requestedBlock=block;
        }
        cache.put(hash,new SoftReference<byte[]>(block));
        received.put(hash,true);
        if (!sentAlready.containsKey(hash)) {
          sendQueue.add(hash);
        }
        hardLoop.add(block);
        int loopSize=hardLoopSize.incrementAndGet();
        while (loopSize > 32768) {
          hardLoop.poll();
          loopSize=hardLoopSize.decrementAndGet();
        }
      }
 catch (      EOFException eof1) {
        eof=true;
        continue;
      }
catch (      IOException ioe) {
        if (in != null) {
          try {
            in.close();
          }
 catch (          IOException ioe2) {
            return null;
          }
        }
        return null;
      }
    }
    return requestedBlock;
  }
}