Program: 85941
Project: 85941
Buggy source:
private void checkoutPart(String pPartNumber,String pRevision,PSFilter filter) throws IOException, UserNotFoundException, WorkspaceNotFoundException, UserNotActiveException, PartMasterNotFoundException, PartRevisionNotFoundException, LoginException, NoSuchAlgorithmException, PartIterationNotFoundException, NotAllowedException, FileAlreadyExistsException, AccessRightException, CreationException {
  PartMaster pm=productS.getPartMaster(new PartMasterKey(workspace,pPartNumber));
  PartRevision pr;
  PartIteration pi;
  if (filter != null) {
    pi=filter.filter(pm).get(0);
    if (pi == null) {
      throw new IllegalArgumentException(LangHelper.getLocalizedMessage("String_Node_Str",user));
    }
    pr=pi.getPartRevision();
    if (null != pRevision && !pr.getVersion().equals(pRevision)) {
      throw new IllegalArgumentException(LangHelper.getLocalizedMessage("String_Node_Str",user));
    }
  }
 else {
    if (pRevision != null) {
      pr=productS.getPartRevision(new PartRevisionKey(workspace,pPartNumber,pRevision));
    }
 else {
      pr=pm.getLastRevision();
    }
    pi=pr.getLastIteration();
  }
  if (!pr.isCheckedOut()) {
    try {
      pr=productS.checkOutPart(new PartRevisionKey(workspace,pPartNumber,pr.getVersion()));
      pi=pr.getLastIteration();
    }
 catch (    Exception e) {
      output.printException(e);
    }
  }
  BinaryResource bin=pi.getNativeCADFile();
  if (bin != null && !noDownload) {
    FileHelper fh=new FileHelper(user,password,output,new AccountsManager().getUserLocale(user));
    fh.downloadNativeCADFile(getServerURL(),path,workspace,pPartNumber,pr,pi,force);
  }
  if (recursive) {
    PartIterationKey partIPK=new PartIterationKey(workspace,pPartNumber,pr.getVersion(),pi.getIteration());
    List<PartUsageLink> usageLinks=productS.getComponents(partIPK);
    for (    PartUsageLink link : usageLinks) {
      PartMaster subPM=link.getComponent();
      checkoutPart(subPM.getNumber(),null,filter);
    }
  }
}

Fixed version (ground truth):
private void checkoutPart(String pPartNumber,String pRevision,PSFilter filter) throws IOException, UserNotFoundException, WorkspaceNotFoundException, UserNotActiveException, PartMasterNotFoundException, PartRevisionNotFoundException, LoginException, NoSuchAlgorithmException, PartIterationNotFoundException, NotAllowedException, FileAlreadyExistsException, AccessRightException, CreationException {
  Locale locale=new AccountsManager().getUserLocale(user);
  PartMaster pm=productS.getPartMaster(new PartMasterKey(workspace,pPartNumber));
  PartRevision pr;
  PartIteration pi;
  output.printInfo(LangHelper.getLocalizedMessage("String_Node_Str",locale) + "String_Node_Str" + pm.getNumber());
  if (filter != null) {
    pi=filter.filter(pm).get(0);
    if (pi == null) {
      throw new IllegalArgumentException(LangHelper.getLocalizedMessage("String_Node_Str",user));
    }
    pr=pi.getPartRevision();
    if (null != pRevision && !pr.getVersion().equals(pRevision)) {
      throw new IllegalArgumentException(LangHelper.getLocalizedMessage("String_Node_Str",user));
    }
  }
 else {
    if (pRevision != null) {
      pr=productS.getPartRevision(new PartRevisionKey(workspace,pPartNumber,pRevision));
    }
 else {
      pr=pm.getLastRevision();
    }
    pi=pr.getLastIteration();
  }
  if (!pr.isCheckedOut()) {
    try {
      pr=productS.checkOutPart(new PartRevisionKey(workspace,pPartNumber,pr.getVersion()));
      pi=pr.getLastIteration();
    }
 catch (    Exception e) {
      output.printException(e);
    }
  }
  BinaryResource bin=pi.getNativeCADFile();
  if (bin != null && !noDownload) {
    FileHelper fh=new FileHelper(user,password,output,locale);
    fh.downloadNativeCADFile(getServerURL(),path,workspace,pPartNumber,pr,pi,force);
  }
  if (recursive) {
    PartIterationKey partIPK=new PartIterationKey(workspace,pPartNumber,pr.getVersion(),pi.getIteration());
    List<PartUsageLink> usageLinks=productS.getComponents(partIPK);
    for (    PartUsageLink link : usageLinks) {
      PartMaster subPM=link.getComponent();
      checkoutPart(subPM.getNumber(),null,filter);
    }
  }
}