Program: 89657
Project: 89657
Buggy source:
/** 
 * Takes a seed list and creates any necessary domains, configurations, and seedlists to enable them to be harvested with the given template and other parameters. <A href="https://gforge.statsbiblioteket.dk/tracker/?group_id=7&atid=105&func=detail&aid=717">Bug 717</A> addresses this issue. Current naming of the seedlists and domainconfigurations are: one of <br> harvestdefinitionname + "_" + templateName + "_" + "UnlimitedBytes" (if maxbytes is negative)<br> harvestdefinitionname + "_" + templateName + "_" + maxBytes + "Bytes" (if maxbytes is zero or postive).
 * @see EventHarvest#addConfigurations(PageContext,I18n,PartialHarvest) for details
 * @param seeds a newline-separated list of the seeds to be added
 * @param templateName the name of the template to be used
 * @param maxBytes Maximum number of bytes to harvest per domain
 * @param maxObjects Maximum number of objects to harvest per domain
 */
public void addSeeds(String seeds,String templateName,long maxBytes,int maxObjects){
  ArgumentNotValid.checkNotNullOrEmpty(seeds,"String_Node_Str");
  ArgumentNotValid.checkNotNullOrEmpty(templateName,"String_Node_Str");
  if (!TemplateDAO.getInstance().exists(templateName)) {
    throw new UnknownID("String_Node_Str" + templateName);
  }
  final String maxbytesSuffix="String_Node_Str";
  String maxBytesS="String_Node_Str" + maxbytesSuffix;
  if (maxBytes >= 0) {
    maxBytesS=Long.toString(maxBytes);
    maxBytesS=maxBytesS + maxbytesSuffix;
  }
  final String maxobjectsSuffix="String_Node_Str";
  String maxObjectsS="String_Node_Str" + maxobjectsSuffix;
  if (maxObjects >= 0) {
    maxObjectsS=Long.toString(maxObjects);
    maxObjectsS=maxObjectsS + maxobjectsSuffix;
  }
  String name=harvestDefName + "String_Node_Str" + templateName+ "String_Node_Str"+ maxBytesS+ "String_Node_Str"+ maxObjectsS;
  String[] seedArray=seeds.split("String_Node_Str");
  Map<String,Set<String>> acceptedSeeds=new HashMap<String,Set<String>>();
  StringBuilder invalidMessage=new StringBuilder("String_Node_Str" + "String_Node_Str");
  boolean valid=true;
  for (  String seed : seedArray) {
    seed=seed.trim();
    if (seed.length() != 0) {
      if (!(seed.startsWith("String_Node_Str") || seed.startsWith("String_Node_Str"))) {
        seed="String_Node_Str" + seed;
      }
      URL url=null;
      try {
        url=new URL(seed);
      }
 catch (      MalformedURLException e) {
        valid=false;
        invalidMessage.append(seed);
        invalidMessage.append('\n');
        continue;
      }
      String host=url.getHost();
      String domainName=DomainUtils.domainNameFromHostname(host);
      if (domainName == null) {
        valid=false;
        invalidMessage.append(seed);
        invalidMessage.append('\n');
        continue;
      }
      Set<String> seedsForDomain=acceptedSeeds.get(domainName);
      if (seedsForDomain == null) {
        seedsForDomain=new HashSet<String>();
      }
      seedsForDomain.add(seed);
      acceptedSeeds.put(domainName,seedsForDomain);
    }
  }
  if (!valid) {
    throw new ArgumentNotValid(invalidMessage.toString());
  }
  for (  Map.Entry<String,Set<String>> entry : acceptedSeeds.entrySet()) {
    String domainName=entry.getKey();
    Domain domain;
    SeedList seedlist=new SeedList(name,"String_Node_Str");
    List<SeedList> seedListList=new ArrayList<SeedList>();
    seedListList.add(seedlist);
    if (DomainDAO.getInstance().exists(domainName)) {
      domain=DomainDAO.getInstance().read(domainName);
      if (!domain.hasSeedList(name)) {
        domain.addSeedList(seedlist);
      }
    }
 else {
      domain=Domain.getDefaultDomain(domainName);
      domain.addSeedList(seedlist);
      DomainDAO.getInstance().create(domain);
    }
    DomainConfiguration dc=null;
    if (domain.hasConfiguration(name)) {
      dc=domain.getConfiguration(name);
    }
 else {
      dc=new DomainConfiguration(name,domain,seedListList,new ArrayList<Password>());
      dc.setOrderXmlName(templateName);
      dc.setMaxBytes(maxBytes);
      dc.setMaxObjects(maxObjects);
      domain.addConfiguration(dc);
    }
    seedlist=domain.getSeedList(name);
    List<String> currentSeeds=seedlist.getSeeds();
    entry.getValue().addAll(currentSeeds);
    List<String> allSeeds=new ArrayList<String>();
    allSeeds.addAll(entry.getValue());
    domain.updateSeedList(new SeedList(name,allSeeds));
    addConfiguration(dc);
    DomainDAO.getInstance().update(domain);
  }
  HarvestDefinition thisInDAO=HarvestDefinitionDAO.getInstance().getHarvestDefinition(this.harvestDefName);
  if (thisInDAO == null) {
    HarvestDefinitionDAO.getInstance().create(this);
  }
 else {
    HarvestDefinitionDAO.getInstance().update(this);
  }
}

Fixed version (ground truth):
/** 
 * Takes a seed list and creates any necessary domains, configurations, and seedlists to enable them to be harvested with the given template and other parameters. <A href="https://sbforge.org/jira/browse/NAS-1317">JIRA issue NAS-1317</A> addresses this issue. Current naming of the seedlists and domainconfigurations are: one of <br> harvestdefinitionname + "_" + templateName + "_" + "UnlimitedBytes" (if maxbytes is negative)<br> harvestdefinitionname + "_" + templateName + "_" + maxBytes + "Bytes" (if maxbytes is zero or postive).
 * @see EventHarvest#addConfigurations(PageContext,I18n,String) for details
 * @param seeds a newline-separated list of the seeds to be added
 * @param templateName the name of the template to be used
 * @param maxBytes Maximum number of bytes to harvest per domain
 * @param maxObjects Maximum number of objects to harvest per domain
 */
public void addSeeds(String seeds,String templateName,long maxBytes,int maxObjects){
  ArgumentNotValid.checkNotNullOrEmpty(seeds,"String_Node_Str");
  ArgumentNotValid.checkNotNullOrEmpty(templateName,"String_Node_Str");
  if (!TemplateDAO.getInstance().exists(templateName)) {
    throw new UnknownID("String_Node_Str" + templateName);
  }
  final String maxbytesSuffix="String_Node_Str";
  String maxBytesS="String_Node_Str" + maxbytesSuffix;
  if (maxBytes >= 0) {
    maxBytesS=Long.toString(maxBytes);
    maxBytesS=maxBytesS + maxbytesSuffix;
  }
  final String maxobjectsSuffix="String_Node_Str";
  String maxObjectsS="String_Node_Str" + maxobjectsSuffix;
  if (maxObjects >= 0) {
    maxObjectsS=Long.toString(maxObjects);
    maxObjectsS=maxObjectsS + maxobjectsSuffix;
  }
  String name=harvestDefName + "String_Node_Str" + templateName+ "String_Node_Str"+ maxBytesS+ "String_Node_Str"+ maxObjectsS;
  String[] seedArray=seeds.split("String_Node_Str");
  Map<String,Set<String>> acceptedSeeds=new HashMap<String,Set<String>>();
  StringBuilder invalidMessage=new StringBuilder("String_Node_Str" + "String_Node_Str");
  boolean valid=true;
  for (  String seed : seedArray) {
    seed=seed.trim();
    if (seed.length() != 0) {
      if (!(seed.startsWith("String_Node_Str") || seed.startsWith("String_Node_Str"))) {
        seed="String_Node_Str" + seed;
      }
      URL url=null;
      try {
        url=new URL(seed);
      }
 catch (      MalformedURLException e) {
        valid=false;
        invalidMessage.append(seed);
        invalidMessage.append('\n');
        continue;
      }
      String host=url.getHost();
      String domainName=DomainUtils.domainNameFromHostname(host);
      if (domainName == null) {
        valid=false;
        invalidMessage.append(seed);
        invalidMessage.append('\n');
        continue;
      }
      Set<String> seedsForDomain=acceptedSeeds.get(domainName);
      if (seedsForDomain == null) {
        seedsForDomain=new HashSet<String>();
      }
      seedsForDomain.add(seed);
      acceptedSeeds.put(domainName,seedsForDomain);
    }
  }
  if (!valid) {
    throw new ArgumentNotValid(invalidMessage.toString());
  }
  for (  Map.Entry<String,Set<String>> entry : acceptedSeeds.entrySet()) {
    String domainName=entry.getKey();
    Domain domain;
    SeedList seedlist=new SeedList(name,"String_Node_Str");
    List<SeedList> seedListList=new ArrayList<SeedList>();
    seedListList.add(seedlist);
    if (DomainDAO.getInstance().exists(domainName)) {
      domain=DomainDAO.getInstance().read(domainName);
      if (!domain.hasSeedList(name)) {
        domain.addSeedList(seedlist);
      }
    }
 else {
      domain=Domain.getDefaultDomain(domainName);
      domain.addSeedList(seedlist);
      DomainDAO.getInstance().create(domain);
    }
    DomainConfiguration dc=null;
    if (domain.hasConfiguration(name)) {
      dc=domain.getConfiguration(name);
    }
 else {
      dc=new DomainConfiguration(name,domain,seedListList,new ArrayList<Password>());
      dc.setOrderXmlName(templateName);
      dc.setMaxBytes(maxBytes);
      dc.setMaxObjects(maxObjects);
      domain.addConfiguration(dc);
    }
    seedlist=domain.getSeedList(name);
    List<String> currentSeeds=seedlist.getSeeds();
    entry.getValue().addAll(currentSeeds);
    List<String> allSeeds=new ArrayList<String>();
    allSeeds.addAll(entry.getValue());
    domain.updateSeedList(new SeedList(name,allSeeds));
    addConfiguration(dc);
    DomainDAO.getInstance().update(domain);
  }
  HarvestDefinition thisInDAO=HarvestDefinitionDAO.getInstance().getHarvestDefinition(this.harvestDefName);
  if (thisInDAO == null) {
    HarvestDefinitionDAO.getInstance().create(this);
  }
 else {
    HarvestDefinitionDAO.getInstance().update(this);
  }
}