Program: 44843
Project: 44843
Buggy source:
/** 
 * Tests to make sure we don't get OutOfMemoryErrors trying to stream files -- typically through copying too many bytes at once.
 * @throws Exception If any unexpected error occurs.
 */
@Test public void testOome() throws Exception {
  final File file=new File(getClass().getSimpleName());
  file.deleteOnExit();
  final OutputStream os=new FileOutputStream(file);
  final byte[] bytes=new byte[10000000];
  for (int i=0; i < bytes.length; i++) {
    bytes[i]=(byte)(i % 127);
  }
  os.write(bytes);
  os.write(bytes);
  os.write(bytes);
  os.write(bytes);
  os.write(bytes);
  os.write(bytes);
  os.write(bytes);
  os.close();
  final RandomAccessFile raf=new RandomAccessFile(file,"String_Node_Str");
  final PriorityBlockingQueue<LongRange> completedRanges=createQueue();
  final URI sha1=Sha1Hasher.createSha1Urn(file);
  final DownloadingFileLauncher launcher=new DownloadingFileLauncher(raf,completedRanges,sha1);
  final File fileCopy=new File(file.getName() + "String_Node_Str");
  fileCopy.deleteOnExit();
  final OutputStream stream=new FileOutputStream(fileCopy);
  final Runnable runner=new Runnable(){
    public void run(){
      try {
        Thread.sleep(400);
      }
 catch (      InterruptedException e) {
        e.printStackTrace();
      }
      final Collection<LongRange> ranges=createRanges(file.length());
      m_log.debug("String_Node_Str" + ranges);
      LongRange minRange=null;
      for (      final LongRange lr : ranges) {
        if (lr.getMinimumLong() != 0L) {
          launcher.onRangeComplete(lr);
        }
 else {
          minRange=lr;
        }
      }
      launcher.onRangeComplete(minRange);
      launcher.onFileComplete();
    }
  }
;
  final Thread thread=new Thread(runner,"String_Node_Str");
  thread.setDaemon(true);
  thread.start();
  launcher.write(stream,true);
  final URI sha1Copy=Sha1Hasher.createSha1Urn(fileCopy);
  assertEquals(sha1,sha1Copy);
  m_log.debug("String_Node_Str" + sha1Copy);
}

Fixed version (ground truth):
/** 
 * Tests to make sure we don't get OutOfMemoryErrors trying to stream files -- typically through copying too many bytes at once.
 * @throws Exception If any unexpected error occurs.
 */
@Test public void testOome() throws Exception {
  final File file=new File(getClass().getSimpleName());
  file.deleteOnExit();
  final OutputStream os=new FileOutputStream(file);
  final byte[] bytes=new byte[10000000];
  for (int i=0; i < bytes.length; i++) {
    bytes[i]=(byte)(i % 127);
  }
  os.write(bytes);
  os.write(bytes);
  os.write(bytes);
  os.write(bytes);
  os.write(bytes);
  os.write(bytes);
  os.write(bytes);
  os.close();
  final RandomAccessFile raf=new RandomAccessFile(file,"String_Node_Str");
  final PriorityBlockingQueue<LongRange> completedRanges=createQueue();
  final URI sha1=Sha1Hasher.createSha1Urn(file);
  final DownloadingFileLauncher launcher=new DownloadingFileLauncher(raf,completedRanges,sha1,file);
  final File fileCopy=new File(file.getName() + "String_Node_Str");
  fileCopy.deleteOnExit();
  final OutputStream stream=new FileOutputStream(fileCopy);
  final Runnable runner=new Runnable(){
    public void run(){
      try {
        Thread.sleep(400);
      }
 catch (      InterruptedException e) {
        e.printStackTrace();
      }
      final Collection<LongRange> ranges=createRanges(file.length());
      m_log.debug("String_Node_Str" + ranges);
      LongRange minRange=null;
      for (      final LongRange lr : ranges) {
        if (lr.getMinimumLong() != 0L) {
          launcher.onRangeComplete(lr);
        }
 else {
          minRange=lr;
        }
      }
      launcher.onRangeComplete(minRange);
      launcher.onFileComplete();
    }
  }
;
  final Thread thread=new Thread(runner,"String_Node_Str");
  thread.setDaemon(true);
  thread.start();
  launcher.write(stream,true);
  final URI sha1Copy=Sha1Hasher.createSha1Urn(fileCopy);
  assertEquals(sha1,sha1Copy);
  m_log.debug("String_Node_Str" + sha1Copy);
}