Program: 134859
Project: 134859
Buggy source:
/** 
 * Load the categories from the CDB. <P> Loads all the category from the CDB and build an internal representation of category. The category is also added to all the alarms having the fault family specified in the XML. <P> All the categories derive from ROOT that is built here as default (in this way the user does ot need to add the ROOT entry in the CDB).
 * @return list of Category entries read from CDB 
 * @throws Exception In case of error reading the values from the CDB
 */
public alma.acs.alarmsystem.generated.Category[] loadCategories() throws Exception {
  if (conf == null) {
    throw new IllegalStateException("String_Node_Str");
  }
  String xml;
  try {
    xml=conf.getConfiguration(CATEGORY_DEFINITION_PATH);
  }
 catch (  Throwable t) {
    throw new RuntimeException("String_Node_Str",t);
  }
  DocumentBuilderFactory factory=DocumentBuilderFactory.newInstance();
  DocumentBuilder builder;
  try {
    builder=factory.newDocumentBuilder();
  }
 catch (  Exception e) {
    throw new Exception("String_Node_Str",e);
  }
  StringReader stringReader=new StringReader(xml);
  InputSource inputSource=new InputSource(stringReader);
  Document doc;
  try {
    doc=builder.parse(inputSource);
    if (doc == null) {
      throw new Exception("String_Node_Str");
    }
  }
 catch (  Exception e) {
    throw new Exception("String_Node_Str" + xml,e);
  }
  NodeList docChilds=doc.getChildNodes();
  if (docChilds == null || docChilds.getLength() != 1) {
    throw new Exception("String_Node_Str");
  }
  Node categoriesNode=docChilds.item(0);
  Unmarshaller FF_unmarshaller=new Unmarshaller(Categories.class);
  FF_unmarshaller.setValidation(false);
  FF_unmarshaller.setWhitespacePreserve(true);
  Categories daoCategories;
  try {
    daoCategories=(Categories)FF_unmarshaller.unmarshal(categoriesNode);
    logger.log(AcsLogLevel.DEBUG,"String_Node_Str");
  }
 catch (  Exception e) {
    throw new Exception("String_Node_Str" + CATEGORY_DEFINITION_PATH,e);
  }
  alma.acs.alarmsystem.generated.Category[] daoCategory=daoCategories.getCategory();
  if (daoCategory == null || daoCategory.length == 0) {
    logger.log(AcsLogLevel.DEBUG,"String_Node_Str");
  }
  addRootCategory();
  for (  alma.acs.alarmsystem.generated.Category category : daoCategory) {
    cern.laser.business.definition.data.CategoryDefinition definition=new cern.laser.business.definition.data.CategoryDefinition(category.getPath(),category.getDescription());
    CategoryImpl ci=new CategoryImpl();
    ci.setAlarmIds(new HashSet());
    ci.setCategoryId(new Integer(nextCatID++));
    ci.setChildrenIds(new HashSet<Integer>());
    ci.setDescription(definition.getDescription());
    ci.setName(definition.getPath());
    ci.setPath(definition.getPath());
    ci.setAlarmIds(new HashSet());
    setParentID(ci);
    categories.put(ci.getCategoryId(),ci);
    catPathToCategory.put(ci.getPath(),ci);
    logger.log(AcsLogLevel.DEBUG,"String_Node_Str" + ci.getName() + "String_Node_Str"+ ci.getCategoryId());
    if (category.hasIsDefault() && category.getIsDefault() == true) {
      if (defaultCategory != null) {
        StringBuilder str=new StringBuilder("String_Node_Str");
        str.append(defaultCategory.getPath());
        str.append("String_Node_Str");
        str.append(category.getPath());
        logger.log(AcsLogLevel.WARNING,str.toString());
      }
 else {
        defaultCategory=ci;
      }
    }
    adjustParentIDs(ci.getName(),ci.getCategoryId());
    for (    alma.acs.alarmsystem.generated.Category cat : daoCategories.getCategory()) {
      String[] families=cat.getAlarms().getFaultFamily();
      for (      String faultFamily : families) {
        assignCategoryToAlarms(ci,faultFamily);
      }
    }
  }
  assignCategoryOfCoreAlarms();
  if (defaultCategory == null) {
    logger.log(AcsLogLevel.WARNING,"String_Node_Str");
  }
 else {
    assignDefaultCategory(defaultCategory);
  }
  return daoCategory;
}

Fixed version (ground truth):
/** 
 * Load the categories from the CDB. <P> Loads all the category from the CDB and build an internal representation of category. The category is also added to all the alarms having the fault family specified in the XML. <P> All the categories derive from ROOT that is built here as default (in this way the user does ot need to add the ROOT entry in the CDB).
 * @return list of Category entries read from CDB 
 * @throws Exception In case of error reading the values from the CDB
 */
public alma.acs.alarmsystem.generated.Category[] loadCategories() throws Exception {
  if (conf == null) {
    throw new IllegalStateException("String_Node_Str");
  }
  String xml;
  try {
    xml=conf.getConfiguration(CATEGORY_DEFINITION_PATH);
  }
 catch (  Throwable t) {
    throw new RuntimeException("String_Node_Str",t);
  }
  DocumentBuilderFactory factory=DocumentBuilderFactory.newInstance();
  DocumentBuilder builder;
  try {
    builder=factory.newDocumentBuilder();
  }
 catch (  Exception e) {
    throw new Exception("String_Node_Str",e);
  }
  StringReader stringReader=new StringReader(xml);
  InputSource inputSource=new InputSource(stringReader);
  Document doc;
  try {
    doc=builder.parse(inputSource);
    if (doc == null) {
      throw new Exception("String_Node_Str");
    }
  }
 catch (  Exception e) {
    throw new Exception("String_Node_Str" + xml,e);
  }
  NodeList docChilds=doc.getChildNodes();
  if (docChilds == null || docChilds.getLength() != 1) {
    throw new Exception("String_Node_Str");
  }
  Node categoriesNode=docChilds.item(0);
  Unmarshaller FF_unmarshaller=new Unmarshaller(Categories.class);
  FF_unmarshaller.setValidation(false);
  FF_unmarshaller.setWhitespacePreserve(true);
  Categories daoCategories;
  try {
    daoCategories=(Categories)FF_unmarshaller.unmarshal(categoriesNode);
    logger.log(AcsLogLevel.DEBUG,"String_Node_Str");
  }
 catch (  Exception e) {
    throw new Exception("String_Node_Str" + CATEGORY_DEFINITION_PATH,e);
  }
  alma.acs.alarmsystem.generated.Category[] daoCategory=daoCategories.getCategory();
  if (daoCategory == null || daoCategory.length == 0) {
    logger.log(AcsLogLevel.DEBUG,"String_Node_Str");
  }
  addRootCategory();
  for (  alma.acs.alarmsystem.generated.Category category : daoCategory) {
    cern.laser.business.definition.data.CategoryDefinition definition=new cern.laser.business.definition.data.CategoryDefinition(category.getPath(),category.getDescription());
    CategoryImpl ci=new CategoryImpl();
    ci.setAlarmIds(new HashSet());
    ci.setCategoryId(new Integer(nextCatID++));
    ci.setChildrenIds(new HashSet<Integer>());
    ci.setDescription(definition.getDescription());
    ci.setName(definition.getPath());
    ci.setPath(definition.getPath());
    ci.setAlarmIds(new HashSet());
    setParentID(ci);
    categories.put(ci.getCategoryId(),ci);
    catPathToCategory.put(ci.getPath(),ci);
    logger.log(AcsLogLevel.DEBUG,"String_Node_Str" + ci.getName() + "String_Node_Str"+ ci.getCategoryId());
    if (category.hasIsDefault() && category.getIsDefault() == true) {
      if (defaultCategory != null) {
        StringBuilder str=new StringBuilder("String_Node_Str");
        str.append(defaultCategory.getPath());
        str.append("String_Node_Str");
        str.append(category.getPath());
        logger.log(AcsLogLevel.WARNING,str.toString());
      }
 else {
        defaultCategory=ci;
      }
    }
    adjustParentIDs(ci.getName(),ci.getCategoryId());
    for (    alma.acs.alarmsystem.generated.Category cat : daoCategories.getCategory()) {
      if (cat.getPath().equals(ci.getPath())) {
        String[] families=cat.getAlarms().getFaultFamily();
        for (        String faultFamily : families) {
          assignCategoryToAlarms(ci,faultFamily);
        }
      }
    }
  }
  assignCategoryOfCoreAlarms();
  if (defaultCategory == null) {
    logger.log(AcsLogLevel.WARNING,"String_Node_Str");
  }
 else {
    assignDefaultCategory(defaultCategory);
  }
  return daoCategory;
}