Program: 44633
Project: 44633
Buggy source:
@SuppressWarnings("String_Node_Str") public <T>T serializeAllTaxonomies(ResourceRepresentationType<T> taxonomyOutput,FetchLevel fetchLevel,boolean prettyPrint){
  ByteArrayOutputStream os=null;
  try {
    Session session=getSession();
    if (taxonomyOutput == null) {
      taxonomyOutput=(ResourceRepresentationType<T>)ResourceRepresentationType.TAXONOMY_LIST;
    }
    if (ResourceRepresentationType.TAXONOMY_INSTANCE.equals(taxonomyOutput) || ResourceRepresentationType.TAXONOMY_LIST.equals(taxonomyOutput)) {
      Node taxonomyRootNode=JcrNodeUtils.getTaxonomyRootNode(session);
      if (!taxonomyRootNode.hasNodes()) {
        if (ResourceRepresentationType.TAXONOMY_INSTANCE.equals(taxonomyOutput)) {
          return null;
        }
 else {
          return (T)new CmsOutcomeImpl<Taxonomy>(0,0,0);
        }
      }
      NodeIterator taxonomyNodes=taxonomyRootNode.getNodes();
      if (taxonomyNodes.getSize() > 1 && ResourceRepresentationType.TAXONOMY_INSTANCE.equals(taxonomyOutput)) {
        throw new CmsException("String_Node_Str");
      }
      CmsOutcome<Taxonomy> outcome=new CmsOutcomeImpl<Taxonomy>(taxonomyNodes.getSize(),0,(int)taxonomyNodes.getSize());
      while (taxonomyNodes.hasNext()) {
        Node taxonomyNode=taxonomyNodes.nextNode();
        Taxonomy taxonomy=taxonomyRenderer.renderTaxonomy(taxonomyNode,null,cmsRepositoryEntityFactoryForActiveClient.newTaxonomy());
        if (fetchLevel != null) {
switch (fetchLevel) {
case ENTITY_AND_CHILDREN:
            taxonomy.getRootTopics();
          break;
case FULL:
        loadAllChildren(taxonomy.getRootTopics());
      break;
default :
    break;
}
}
outcome.getResults().add(taxonomy);
}
return (T)outcome;
}
 else if (ResourceRepresentationType.XML.equals(taxonomyOutput) || ResourceRepresentationType.JSON.equals(taxonomyOutput)) {
os=new ByteArrayOutputStream();
TaxonomyCriteria taxonomyCriteria=CmsCriteriaFactory.newTaxonomyCriteria();
taxonomyCriteria.getRenderProperties().prettyPrint(prettyPrint);
serializationDao.serializeSearchResults(session,taxonomyCriteria,os,fetchLevel,taxonomyOutput,false);
return (T)new String(os.toByteArray(),"String_Node_Str");
}
 else {
throw new CmsException("String_Node_Str" + taxonomyOutput);
}
}
 catch (RepositoryException ex) {
throw new CmsException(ex);
}
catch (Exception e) {
throw new CmsException(e);
}
 finally {
IOUtils.closeQuietly(os);
}
}

Fixed version (ground truth):
@SuppressWarnings("String_Node_Str") public <T>T serializeAllTaxonomies(ResourceRepresentationType<T> taxonomyOutput,FetchLevel fetchLevel,boolean prettyPrint){
  ByteArrayOutputStream os=null;
  try {
    Session session=getSession();
    if (taxonomyOutput == null) {
      taxonomyOutput=(ResourceRepresentationType<T>)ResourceRepresentationType.TAXONOMY_LIST;
    }
    if (ResourceRepresentationType.TAXONOMY_INSTANCE.equals(taxonomyOutput) || ResourceRepresentationType.TAXONOMY_LIST.equals(taxonomyOutput)) {
      Node taxonomyRootNode=JcrNodeUtils.getTaxonomyRootNode(session);
      if (!taxonomyRootNode.hasNodes()) {
        if (ResourceRepresentationType.TAXONOMY_INSTANCE.equals(taxonomyOutput)) {
          return null;
        }
 else {
          return (T)new CmsOutcomeImpl<Taxonomy>(0,0,0);
        }
      }
      NodeIterator taxonomyNodes=taxonomyRootNode.getNodes();
      if (taxonomyNodes.getSize() > 1 && ResourceRepresentationType.TAXONOMY_INSTANCE.equals(taxonomyOutput)) {
        throw new CmsException("String_Node_Str");
      }
      CmsOutcome<Taxonomy> outcome=new CmsOutcomeImpl<Taxonomy>(taxonomyNodes.getSize(),0,(int)taxonomyNodes.getSize());
      while (taxonomyNodes.hasNext()) {
        Node taxonomyNode=taxonomyNodes.nextNode();
        Taxonomy taxonomy=taxonomyRenderer.renderTaxonomy(taxonomyNode,null,cmsRepositoryEntityFactoryForActiveClient.newTaxonomy());
        if (fetchLevel != null) {
switch (fetchLevel) {
case ENTITY_AND_CHILDREN:
            taxonomy.getRootTopics();
          break;
case FULL:
        loadAllChildren(taxonomy.getRootTopics());
      break;
default :
    break;
}
}
outcome.getResults().add(taxonomy);
}
return (T)outcome;
}
 else if (ResourceRepresentationType.XML.equals(taxonomyOutput) || ResourceRepresentationType.JSON.equals(taxonomyOutput)) {
os=new ByteArrayOutputStream();
TaxonomyCriteria taxonomyCriteria=CmsCriteriaFactory.newTaxonomyCriteria();
SerializationConfiguration serializationConfiguration=SerializationConfiguration.taxonomy().prettyPrint(prettyPrint).representationType(taxonomyOutput).build();
serializationDao.serializeSearchResults(session,taxonomyCriteria,os,fetchLevel,serializationConfiguration);
return (T)new String(os.toByteArray(),"String_Node_Str");
}
 else {
throw new CmsException("String_Node_Str" + taxonomyOutput);
}
}
 catch (RepositoryException ex) {
throw new CmsException(ex);
}
catch (Exception e) {
throw new CmsException(e);
}
 finally {
IOUtils.closeQuietly(os);
}
}