Program: 86006
Project: 86006
Buggy source:
private List<PartUsageLink> createComponents(String workspaceId,List<PartUsageLinkDTO> pComponents) throws EntityNotFoundException, EntityAlreadyExistsException, AccessRightException, NotAllowedException, CreationException, UserNotActiveException {
  List<PartUsageLink> components=new ArrayList<>();
  for (  PartUsageLinkDTO partUsageLinkDTO : pComponents) {
    PartMaster component=findOrCreatePartMaster(workspaceId,partUsageLinkDTO.getComponent());
    if (component != null) {
      PartUsageLink partUsageLink=new PartUsageLink();
      List<CADInstance> cadInstances=new ArrayList<>();
      List<PartSubstituteLink> partSubstituteLinks=new ArrayList<>();
      if (partUsageLinkDTO.getCadInstances() != null) {
        for (        CADInstanceDTO cadInstanceDTO : partUsageLinkDTO.getCadInstances()) {
          cadInstances.add(new CADInstance(cadInstanceDTO.getTx(),cadInstanceDTO.getTy(),cadInstanceDTO.getTz(),cadInstanceDTO.getRx(),cadInstanceDTO.getRy(),cadInstanceDTO.getRz()));
        }
      }
 else       if (partUsageLinkDTO.getUnit() == null || partUsageLinkDTO.getUnit().isEmpty()) {
        for (double i=0; i < partUsageLinkDTO.getAmount(); i++) {
          cadInstances.add(new CADInstance(0,0,0,0,0,0));
        }
      }
 else {
        cadInstances.add(new CADInstance(0,0,0,0,0,0));
      }
      for (      PartSubstituteLinkDTO substituteLinkDTO : partUsageLinkDTO.getSubstitutes()) {
        PartMaster substitute=findOrCreatePartMaster(workspaceId,substituteLinkDTO.getSubstitute());
        if (substitute != null) {
          PartSubstituteLink partSubstituteLink=mapper.map(substituteLinkDTO,PartSubstituteLink.class);
          List<CADInstance> subCADInstances=new ArrayList<>();
          if (substituteLinkDTO.getCadInstances() != null) {
            for (            CADInstanceDTO cadInstanceDTO : substituteLinkDTO.getCadInstances()) {
              subCADInstances.add(new CADInstance(cadInstanceDTO.getTx(),cadInstanceDTO.getTy(),cadInstanceDTO.getTz(),cadInstanceDTO.getRx(),cadInstanceDTO.getRy(),cadInstanceDTO.getRz()));
            }
          }
 else           if (substituteLinkDTO.getUnit() == null || substituteLinkDTO.getUnit().isEmpty()) {
            for (double i=0; i < substituteLinkDTO.getAmount(); i++) {
              subCADInstances.add(new CADInstance(0,0,0,0,0,0));
            }
          }
 else {
            cadInstances.add(new CADInstance(0,0,0,0,0,0));
          }
          partSubstituteLink.setCadInstances(subCADInstances);
          partSubstituteLink.setSubstitute(substitute);
          partSubstituteLinks.add(partSubstituteLink);
        }
      }
      partUsageLink.setComponent(component);
      partUsageLink.setAmount(partUsageLinkDTO.getAmount());
      partUsageLink.setComment(partUsageLinkDTO.getComment());
      partUsageLink.setCadInstances(cadInstances);
      partUsageLink.setUnit(partUsageLinkDTO.getUnit());
      partUsageLink.setSubstitutes(partSubstituteLinks);
      components.add(partUsageLink);
    }
  }
  return components;
}

Fixed version (ground truth):
private List<PartUsageLink> createComponents(String workspaceId,List<PartUsageLinkDTO> pComponents) throws EntityNotFoundException, EntityAlreadyExistsException, AccessRightException, NotAllowedException, CreationException, UserNotActiveException {
  List<PartUsageLink> components=new ArrayList<>();
  for (  PartUsageLinkDTO partUsageLinkDTO : pComponents) {
    PartMaster component=findOrCreatePartMaster(workspaceId,partUsageLinkDTO.getComponent());
    if (component != null) {
      PartUsageLink partUsageLink=new PartUsageLink();
      List<CADInstance> cadInstances=new ArrayList<>();
      List<PartSubstituteLink> partSubstituteLinks=new ArrayList<>();
      if (partUsageLinkDTO.getCadInstances() != null) {
        for (        CADInstanceDTO cadInstanceDTO : partUsageLinkDTO.getCadInstances()) {
          cadInstances.add(new CADInstance(cadInstanceDTO.getTx(),cadInstanceDTO.getTy(),cadInstanceDTO.getTz(),cadInstanceDTO.getRx(),cadInstanceDTO.getRy(),cadInstanceDTO.getRz()));
        }
      }
 else       if (partUsageLinkDTO.getUnit() == null || partUsageLinkDTO.getUnit().isEmpty()) {
        for (double i=0; i < partUsageLinkDTO.getAmount(); i++) {
          cadInstances.add(new CADInstance(0,0,0,0,0,0));
        }
      }
 else {
        cadInstances.add(new CADInstance(0,0,0,0,0,0));
      }
      for (      PartSubstituteLinkDTO substituteLinkDTO : partUsageLinkDTO.getSubstitutes()) {
        PartMaster substitute=findOrCreatePartMaster(workspaceId,substituteLinkDTO.getSubstitute());
        if (substitute != null) {
          PartSubstituteLink partSubstituteLink=mapper.map(substituteLinkDTO,PartSubstituteLink.class);
          List<CADInstance> subCADInstances=new ArrayList<>();
          if (substituteLinkDTO.getCadInstances() != null) {
            for (            CADInstanceDTO cadInstanceDTO : substituteLinkDTO.getCadInstances()) {
              subCADInstances.add(new CADInstance(cadInstanceDTO.getTx(),cadInstanceDTO.getTy(),cadInstanceDTO.getTz(),cadInstanceDTO.getRx(),cadInstanceDTO.getRy(),cadInstanceDTO.getRz()));
            }
          }
 else           if (substituteLinkDTO.getUnit() == null || substituteLinkDTO.getUnit().isEmpty()) {
            for (double i=0; i < substituteLinkDTO.getAmount(); i++) {
              subCADInstances.add(new CADInstance(0,0,0,0,0,0));
            }
          }
 else {
            subCADInstances.add(new CADInstance(0,0,0,0,0,0));
          }
          partSubstituteLink.setCadInstances(subCADInstances);
          partSubstituteLink.setSubstitute(substitute);
          partSubstituteLinks.add(partSubstituteLink);
        }
      }
      partUsageLink.setComponent(component);
      partUsageLink.setAmount(partUsageLinkDTO.getAmount());
      partUsageLink.setComment(partUsageLinkDTO.getComment());
      partUsageLink.setCadInstances(cadInstances);
      partUsageLink.setUnit(partUsageLinkDTO.getUnit());
      partUsageLink.setSubstitutes(partSubstituteLinks);
      components.add(partUsageLink);
    }
  }
  return components;
}