Program: 125353
Project: 125353
Buggy source:
public void downloadFile(IProgressMonitor monitor,MavenArtifact artifact,File target) throws Exception {
  if (monitor == null) {
    monitor=new NullProgressMonitor();
  }
  if (artifact == null) {
    return;
  }
  final String reletivePath=PomUtil.getArtifactPath(artifact);
  if (reletivePath == null) {
    return;
  }
  final Authenticator defaultAuthenticator=NetworkUtil.getDefaultAuthenticator();
  boolean success=false;
  BufferedInputStream bis=null;
  BufferedOutputStream bos=null;
  HttpURLConnection httpURLConnection=null;
  try {
    if (StringUtils.isNotEmpty(nexusUser)) {
      Authenticator.setDefault(new Authenticator(){
        @Override protected PasswordAuthentication getPasswordAuthentication(){
          return new PasswordAuthentication(nexusUser,nexusPass);
        }
      }
);
    }
    httpURLConnection=NexusServerUtils.getHttpURLConnection(nexusURL,reletivePath,nexusUser,new String(nexusPass));
    if (monitor.isCanceled()) {
      throw new OperationCanceledException();
    }
    InputStream inputStream=httpURLConnection.getInputStream();
    bis=new BufferedInputStream(inputStream);
    bos=new BufferedOutputStream(new FileOutputStream(target));
    byte[] buf=new byte[BUFFER_SIZE];
    int bytesRead=-1;
    while ((bytesRead=bis.read(buf)) != -1) {
      if (monitor.isCanceled()) {
        throw new OperationCanceledException();
      }
      bos.write(buf,0,bytesRead);
    }
    bos.flush();
    success=true;
  }
  finally {
    if (bis != null) {
      try {
        bis.close();
      }
 catch (      IOException e) {
        ExceptionHandler.process(e);
      }
    }
    if (bos != null) {
      try {
        bos.close();
      }
 catch (      IOException e) {
        ExceptionHandler.process(e);
      }
    }
    if (httpURLConnection != null) {
      httpURLConnection.disconnect();
    }
    if (!success && target.exists() && target.isFile()) {
      target.delete();
    }
    Authenticator.setDefault(defaultAuthenticator);
  }
}

Fixed version (ground truth):
public void downloadFile(IProgressMonitor monitor,MavenArtifact artifact,File target) throws Exception {
  if (monitor == null) {
    monitor=new NullProgressMonitor();
  }
  if (artifact == null) {
    return;
  }
  final String reletivePath=PomUtil.getArtifactPath(artifact);
  if (reletivePath == null) {
    return;
  }
  final Authenticator defaultAuthenticator=NetworkUtil.getDefaultAuthenticator();
  boolean success=false;
  BufferedInputStream bis=null;
  BufferedOutputStream bos=null;
  HttpURLConnection httpURLConnection=null;
  try {
    setAuthenticator();
    httpURLConnection=NexusServerUtils.getHttpURLConnection(getNexusURL(),reletivePath,getNexusUser(),getNexusPassStr());
    if (monitor.isCanceled()) {
      throw new OperationCanceledException();
    }
    InputStream inputStream=httpURLConnection.getInputStream();
    bis=new BufferedInputStream(inputStream);
    bos=new BufferedOutputStream(new FileOutputStream(target));
    byte[] buf=new byte[BUFFER_SIZE];
    int bytesRead=-1;
    while ((bytesRead=bis.read(buf)) != -1) {
      if (monitor.isCanceled()) {
        throw new OperationCanceledException();
      }
      bos.write(buf,0,bytesRead);
    }
    bos.flush();
    success=true;
  }
  finally {
    if (bis != null) {
      try {
        bis.close();
      }
 catch (      IOException e) {
        ExceptionHandler.process(e);
      }
    }
    if (bos != null) {
      try {
        bos.close();
      }
 catch (      IOException e) {
        ExceptionHandler.process(e);
      }
    }
    if (httpURLConnection != null) {
      httpURLConnection.disconnect();
    }
    if (!success && target.exists() && target.isFile()) {
      target.delete();
    }
    Authenticator.setDefault(defaultAuthenticator);
  }
}