Program: 170766
Project: 170766
Buggy source:
protected void enqueueCheckRequestSupport(final DiskManagerCheckRequest request,final DiskManagerCheckRequestListener listener,boolean read_flush){
  if (!checking_enabled) {
    listener.checkCompleted(request,true);
    return;
  }
  final int pieceNumber=request.getPieceNumber();
  try {
    final byte[] required_hash=disk_manager.getPieceHash(pieceNumber);
    final DMPieceList pieceList=disk_manager.getPieceList(pieceNumber);
    try {
      boolean all_compact=pieceList.size() > 0;
      for (int i=0; i < pieceList.size(); i++) {
        DMPieceMapEntry piece_entry=pieceList.get(i);
        DiskManagerFileInfoImpl file_info=piece_entry.getFile();
        CacheFile cache_file=file_info.getCacheFile();
        if (cache_file.compareLength(piece_entry.getOffset()) < 0) {
          listener.checkCompleted(request,false);
          return;
        }
        if (all_compact) {
          int st=cache_file.getStorageType();
          if ((st != CacheFile.CT_COMPACT && st != CacheFile.CT_PIECE_REORDER_COMPACT) || file_info.getNbPieces() <= 2) {
            all_compact=false;
          }
        }
      }
      if (all_compact) {
        listener.checkCompleted(request,false);
        return;
      }
    }
 catch (    Throwable e) {
      listener.checkCancelled(request);
      return;
    }
    int this_piece_length=disk_manager.getPieceLength(pieceNumber);
    DiskManagerReadRequest read_request=disk_manager.createReadRequest(pieceNumber,0,this_piece_length);
    try {
      this_mon.enter();
      if (stopped) {
        listener.checkCancelled(request);
        return;
      }
      async_reads++;
    }
  finally {
      this_mon.exit();
    }
    read_request.setFlush(read_flush);
    read_request.setUseCache(!request.isAdHoc());
    disk_manager.enqueueReadRequest(read_request,new DiskManagerReadRequestListener(){
      @Override public void readCompleted(      DiskManagerReadRequest read_request,      DirectByteBuffer buffer){
        complete();
        try {
          this_mon.enter();
          if (stopped) {
            buffer.returnToPool();
            listener.checkCancelled(request);
            return;
          }
          async_checks++;
        }
  finally {
          this_mon.exit();
        }
        if (buffer.getFlag(DirectByteBuffer.FL_CONTAINS_TRANSIENT_DATA)) {
          try {
            buffer.returnToPool();
            listener.checkCompleted(request,false);
          }
  finally {
            try {
              this_mon.enter();
              async_checks--;
              if (stopped) {
                async_check_sem.release();
              }
            }
  finally {
              this_mon.exit();
            }
          }
        }
 else {
          try {
            final DirectByteBuffer f_buffer=buffer;
            ConcurrentHasher.getSingleton().addRequest(buffer.getBuffer(DirectByteBuffer.SS_DW),new ConcurrentHasherRequestListener(){
              @Override public void complete(              ConcurrentHasherRequest hash_request){
                int async_result=3;
                try {
                  byte[] actual_hash=hash_request.getResult();
                  if (actual_hash != null) {
                    request.setHash(actual_hash);
                    async_result=1;
                    for (int i=0; i < actual_hash.length; i++) {
                      if (actual_hash[i] != required_hash[i]) {
                        async_result=2;
                        break;
                      }
                    }
                  }
                }
  finally {
                  try {
                    if (async_result == 1) {
                      try {
                        for (int i=0; i < pieceList.size(); i++) {
                          DMPieceMapEntry piece_entry=pieceList.get(i);
                          DiskManagerFileInfoImpl file_info=piece_entry.getFile();
                          if (file_info.getLength() > 0 || !file_info.isSkipped()) {
                            CacheFile cache_file=file_info.getCacheFile();
                            cache_file.setPieceComplete(pieceNumber,f_buffer);
                          }
                        }
                      }
 catch (                      Throwable e) {
                        f_buffer.returnToPool();
                        Debug.out(e);
                        listener.checkFailed(request,e);
                        return;
                      }
                    }
                    f_buffer.returnToPool();
                    if (async_result == 1) {
                      listener.checkCompleted(request,true);
                    }
 else                     if (async_result == 2) {
                      listener.checkCompleted(request,false);
                    }
 else {
                      listener.checkCancelled(request);
                    }
                  }
  finally {
                    try {
                      this_mon.enter();
                      async_checks--;
                      if (stopped) {
                        async_check_sem.release();
                      }
                    }
  finally {
                      this_mon.exit();
                    }
                  }
                }
              }
            }
,request.isLowPriority());
          }
 catch (          Throwable e) {
            Debug.printStackTrace(e);
            buffer.returnToPool();
            listener.checkFailed(request,e);
          }
        }
      }
      @Override public void readFailed(      DiskManagerReadRequest read_request,      Throwable cause){
        complete();
        listener.checkFailed(request,cause);
      }
      @Override public int getPriority(){
        return (checking_read_priority ? 0 : -1);
      }
      @Override public void requestExecuted(      long bytes){
      }
      protected void complete(){
        try {
          this_mon.enter();
          async_reads--;
          if (stopped) {
            async_read_sem.release();
          }
        }
  finally {
          this_mon.exit();
        }
      }
    }
);
  }
 catch (  Throwable e) {
    disk_manager.setFailed("String_Node_Str" + Debug.getNestedExceptionMessage(e));
    Debug.printStackTrace(e);
    listener.checkFailed(request,e);
  }
}

Fixed version (ground truth):
protected void enqueueCheckRequestSupport(final DiskManagerCheckRequest request,final DiskManagerCheckRequestListener listener,boolean read_flush){
  if (!checking_enabled) {
    listener.checkCompleted(request,true);
    return;
  }
  final int pieceNumber=request.getPieceNumber();
  try {
    final byte[] required_hash=disk_manager.getPieceHash(pieceNumber);
    final DMPieceList pieceList=disk_manager.getPieceList(pieceNumber);
    try {
      boolean all_compact=pieceList.size() > 0;
      for (int i=0; i < pieceList.size(); i++) {
        DMPieceMapEntry piece_entry=pieceList.get(i);
        DiskManagerFileInfoImpl file_info=piece_entry.getFile();
        CacheFile cache_file=file_info.getCacheFile();
        if (cache_file.compareLength(piece_entry.getOffset()) < 0) {
          listener.checkCompleted(request,false);
          return;
        }
        if (all_compact) {
          int st=cache_file.getStorageType();
          if ((st != CacheFile.CT_COMPACT && st != CacheFile.CT_PIECE_REORDER_COMPACT) || file_info.getNbPieces() <= 2) {
            all_compact=false;
          }
        }
      }
      if (all_compact) {
        listener.checkCompleted(request,false);
        return;
      }
    }
 catch (    Throwable e) {
      listener.checkCancelled(request);
      return;
    }
    int this_piece_length=disk_manager.getPieceLength(pieceNumber);
    DiskManagerReadRequest read_request=disk_manager.createReadRequest(pieceNumber,0,this_piece_length);
    try {
      this_mon.enter();
      if (stopped) {
        listener.checkCancelled(request);
        return;
      }
      async_reads++;
    }
  finally {
      this_mon.exit();
    }
    read_request.setFlush(read_flush);
    read_request.setUseCache(!request.isAdHoc());
    disk_manager.enqueueReadRequest(read_request,new DiskManagerReadRequestListener(){
      @Override public void readCompleted(      DiskManagerReadRequest read_request,      DirectByteBuffer buffer){
        complete();
        try {
          this_mon.enter();
          if (stopped) {
            buffer.returnToPool();
            listener.checkCancelled(request);
            return;
          }
          async_checks++;
        }
  finally {
          this_mon.exit();
        }
        if (buffer.getFlag(DirectByteBuffer.FL_CONTAINS_TRANSIENT_DATA)) {
          try {
            buffer.returnToPool();
            listener.checkCompleted(request,false);
          }
  finally {
            try {
              this_mon.enter();
              async_checks--;
              if (stopped) {
                async_check_sem.release();
              }
            }
  finally {
              this_mon.exit();
            }
          }
        }
 else {
          try {
            final DirectByteBuffer f_buffer=buffer;
            ConcurrentHasher.getSingleton().addRequest(buffer.getBuffer(DirectByteBuffer.SS_DW),new ConcurrentHasherRequestListener(){
              @Override public void complete(              ConcurrentHasherRequest hash_request){
                int async_result=3;
                try {
                  byte[] actual_hash=hash_request.getResult();
                  if (actual_hash != null) {
                    request.setHash(actual_hash);
                    async_result=1;
                    for (int i=0; i < actual_hash.length; i++) {
                      if (actual_hash[i] != required_hash[i]) {
                        async_result=2;
                        break;
                      }
                    }
                  }
                }
  finally {
                  try {
                    if (async_result == 1) {
                      try {
                        for (int i=0; i < pieceList.size(); i++) {
                          DMPieceMapEntry piece_entry=pieceList.get(i);
                          DiskManagerFileInfoImpl file_info=piece_entry.getFile();
                          if (file_info.getLength() > 0 || !file_info.isSkipped()) {
                            CacheFile cache_file=file_info.getCacheFile();
                            if (!read_flush && file_info.getStorageType() == DiskManagerFileInfoImpl.ST_REORDER) {
                              cache_file.flushCache(piece_entry.getOffset(),piece_entry.getLength());
                            }
                            cache_file.setPieceComplete(pieceNumber,f_buffer);
                          }
                        }
                      }
 catch (                      Throwable e) {
                        f_buffer.returnToPool();
                        Debug.out(e);
                        listener.checkFailed(request,e);
                        return;
                      }
                    }
                    f_buffer.returnToPool();
                    if (async_result == 1) {
                      listener.checkCompleted(request,true);
                    }
 else                     if (async_result == 2) {
                      listener.checkCompleted(request,false);
                    }
 else {
                      listener.checkCancelled(request);
                    }
                  }
  finally {
                    try {
                      this_mon.enter();
                      async_checks--;
                      if (stopped) {
                        async_check_sem.release();
                      }
                    }
  finally {
                      this_mon.exit();
                    }
                  }
                }
              }
            }
,request.isLowPriority());
          }
 catch (          Throwable e) {
            Debug.printStackTrace(e);
            buffer.returnToPool();
            listener.checkFailed(request,e);
          }
        }
      }
      @Override public void readFailed(      DiskManagerReadRequest read_request,      Throwable cause){
        complete();
        listener.checkFailed(request,cause);
      }
      @Override public int getPriority(){
        return (checking_read_priority ? 0 : -1);
      }
      @Override public void requestExecuted(      long bytes){
      }
      protected void complete(){
        try {
          this_mon.enter();
          async_reads--;
          if (stopped) {
            async_read_sem.release();
          }
        }
  finally {
          this_mon.exit();
        }
      }
    }
);
  }
 catch (  Throwable e) {
    disk_manager.setFailed("String_Node_Str" + Debug.getNestedExceptionMessage(e));
    Debug.printStackTrace(e);
    listener.checkFailed(request,e);
  }
}