Program: 51941
Project: 51941
Buggy source:
@Override public void additionalIndex(Context context,DSpaceObject dso,SolrInputDocument document){
  if (!(dso instanceof Item)) {
    return;
  }
  Item item=(Item)dso;
  BrowseIndex[] bis;
  try {
    bis=BrowseIndex.getBrowseIndices();
  }
 catch (  BrowseException e) {
    log.error(e.getMessage(),e);
    throw new IllegalStateException(e);
  }
  for (  BrowseIndex bi : bis) {
    log.debug("String_Node_Str" + item.getID() + "String_Node_Str"+ bi.getTableName());
    if (bi.isMetadataIndex()) {
      Set<String> distFValues=new HashSet<String>();
      Set<String> distFVal=new HashSet<String>();
      Set<String> distFAuths=new HashSet<String>();
      Set<String> distValuesForAC=new HashSet<String>();
      if (item.isArchived() || item.isWithdrawn()) {
        for (int mdIdx=0; mdIdx < bi.getMetadataCount(); mdIdx++) {
          String[] md=bi.getMdBits(mdIdx);
          List<MetadataValue> values=itemService.getMetadata(item,md[0],md[1],md[2],Item.ANY);
          if (values != null && values.size() > 0) {
            int minConfidence=metadataAuthorityService.getMinConfidence(values.get(0).getMetadataField());
            boolean ignoreAuthority=DSpaceServicesFactory.getInstance().getConfigurationService().getPropertyAsType("String_Node_Str" + bi.getName(),DSpaceServicesFactory.getInstance().getConfigurationService().getPropertyAsType("String_Node_Str",new Boolean(false)),true);
            for (int x=0; x < values.size(); x++) {
              if (StringUtils.isEmpty(values.get(x).getValue())) {
                log.error("String_Node_Str" + item.getID() + "String_Node_Str"+ values.get(x).getMetadataField().toString());
              }
 else {
                if (bi.isAuthorityIndex() && (values.get(x).getAuthority() == null || values.get(x).getConfidence() < minConfidence)) {
                  log.debug("String_Node_Str" + item.getID() + "String_Node_Str"+ values.get(x).getMetadataField().toString()+ "String_Node_Str"+ values.get(x).getValue()+ "String_Node_Str"+ values.get(x).getAuthority()+ "String_Node_Str"+ values.get(x).getConfidence()+ "String_Node_Str");
                  continue;
                }
                if ((ignoreAuthority && !bi.isAuthorityIndex()) || (values.get(x).getAuthority() != null && values.get(x).getConfidence() >= minConfidence)) {
                  distFAuths.add(values.get(x).getAuthority());
                  distValuesForAC.add(values.get(x).getValue());
                  String preferedLabel=null;
                  boolean ignorePrefered=DSpaceServicesFactory.getInstance().getConfigurationService().getPropertyAsType("String_Node_Str" + bi.getName(),DSpaceServicesFactory.getInstance().getConfigurationService().getPropertyAsType("String_Node_Str",new Boolean(false)),true);
                  if (!ignorePrefered) {
                    preferedLabel=choiceAuthorityService.getLabel(values.get(x),values.get(x).getLanguage());
                  }
                  List<String> variants=null;
                  boolean ignoreVariants=DSpaceServicesFactory.getInstance().getConfigurationService().getPropertyAsType("String_Node_Str" + bi.getName(),DSpaceServicesFactory.getInstance().getConfigurationService().getPropertyAsType("String_Node_Str",new Boolean(false)),true);
                  if (!ignoreVariants) {
                    variants=choiceAuthorityService.getVariants(values.get(x));
                  }
                  if (StringUtils.isNotBlank(preferedLabel)) {
                    String nLabel=OrderFormat.makeSortString(preferedLabel,values.get(x).getLanguage(),bi.getDataType());
                    distFValues.add(nLabel + SolrServiceImpl.FILTER_SEPARATOR + preferedLabel+ SolrServiceImpl.AUTHORITY_SEPARATOR+ values.get(x).getAuthority());
                    distValuesForAC.add(preferedLabel);
                  }
                  if (variants != null) {
                    for (                    String var : variants) {
                      String nVal=OrderFormat.makeSortString(var,values.get(x).getLanguage(),bi.getDataType());
                      distFValues.add(nVal + SolrServiceImpl.FILTER_SEPARATOR + var+ SolrServiceImpl.AUTHORITY_SEPARATOR+ values.get(x).getAuthority());
                      distValuesForAC.add(var);
                    }
                  }
                }
 else {
                  String nVal=OrderFormat.makeSortString(values.get(x).getValue(),values.get(x).getLanguage(),bi.getDataType());
                  distFValues.add(nVal + SolrServiceImpl.FILTER_SEPARATOR + values.get(x).getValue());
                  distFVal.add(values.get(x).getValue());
                  distValuesForAC.add(values.get(x).getValue());
                }
              }
            }
          }
        }
      }
      for (      String facet : distFValues) {
        document.addField(bi.getDistinctTableName() + "String_Node_Str",facet);
      }
      for (      String facet : distFAuths) {
        document.addField(bi.getDistinctTableName() + "String_Node_Str",facet);
      }
      for (      String facet : distValuesForAC) {
        document.addField(bi.getDistinctTableName() + "String_Node_Str",facet);
      }
      for (      String facet : distFVal) {
        document.addField(bi.getDistinctTableName() + "String_Node_Str",facet);
      }
    }
  }
  try {
    for (    SortOption so : SortOption.getSortOptions()) {
      List<MetadataValue> dcvalue=itemService.getMetadataByMetadataString(item,so.getMetadata());
      if (dcvalue != null && dcvalue.size() > 0) {
        String nValue=OrderFormat.makeSortString(dcvalue.get(0).getValue(),dcvalue.get(0).getLanguage(),so.getType());
        document.addField("String_Node_Str" + so.getNumber() + "String_Node_Str",nValue);
      }
    }
  }
 catch (  SortException e) {
    throw new RuntimeException(e.getMessage(),e);
  }
}

Fixed version (ground truth):
@Override public void additionalIndex(Context context,DSpaceObject dso,SolrInputDocument document){
  if (!(dso instanceof Item)) {
    return;
  }
  Item item=(Item)dso;
  BrowseIndex[] bis;
  try {
    bis=BrowseIndex.getBrowseIndices();
  }
 catch (  BrowseException e) {
    log.error(e.getMessage(),e);
    throw new IllegalStateException(e);
  }
  for (  BrowseIndex bi : bis) {
    log.debug("String_Node_Str" + item.getID() + "String_Node_Str"+ bi.getTableName());
    if (bi.isMetadataIndex()) {
      bi.generateMdBits();
      Set<String> distFValues=new HashSet<String>();
      Set<String> distFVal=new HashSet<String>();
      Set<String> distFAuths=new HashSet<String>();
      Set<String> distValuesForAC=new HashSet<String>();
      if (item.isArchived() || item.isWithdrawn()) {
        for (int mdIdx=0; mdIdx < bi.getMetadataCount(); mdIdx++) {
          String[] md=bi.getMdBits(mdIdx);
          List<MetadataValue> values=itemService.getMetadata(item,md[0],md[1],md[2],Item.ANY);
          if (values != null && values.size() > 0) {
            int minConfidence=metadataAuthorityService.getMinConfidence(values.get(0).getMetadataField());
            boolean ignoreAuthority=DSpaceServicesFactory.getInstance().getConfigurationService().getPropertyAsType("String_Node_Str" + bi.getName(),DSpaceServicesFactory.getInstance().getConfigurationService().getPropertyAsType("String_Node_Str",new Boolean(false)),true);
            for (int x=0; x < values.size(); x++) {
              if (StringUtils.isEmpty(values.get(x).getValue())) {
                log.error("String_Node_Str" + item.getID() + "String_Node_Str"+ values.get(x).getMetadataField().toString());
              }
 else {
                if (bi.isAuthorityIndex() && (values.get(x).getAuthority() == null || values.get(x).getConfidence() < minConfidence)) {
                  log.debug("String_Node_Str" + item.getID() + "String_Node_Str"+ values.get(x).getMetadataField().toString()+ "String_Node_Str"+ values.get(x).getValue()+ "String_Node_Str"+ values.get(x).getAuthority()+ "String_Node_Str"+ values.get(x).getConfidence()+ "String_Node_Str");
                  continue;
                }
                if ((ignoreAuthority && !bi.isAuthorityIndex()) || (values.get(x).getAuthority() != null && values.get(x).getConfidence() >= minConfidence)) {
                  distFAuths.add(values.get(x).getAuthority());
                  distValuesForAC.add(values.get(x).getValue());
                  String preferedLabel=null;
                  boolean ignorePrefered=DSpaceServicesFactory.getInstance().getConfigurationService().getPropertyAsType("String_Node_Str" + bi.getName(),DSpaceServicesFactory.getInstance().getConfigurationService().getPropertyAsType("String_Node_Str",new Boolean(false)),true);
                  if (!ignorePrefered) {
                    preferedLabel=choiceAuthorityService.getLabel(values.get(x),values.get(x).getLanguage());
                  }
                  List<String> variants=null;
                  boolean ignoreVariants=DSpaceServicesFactory.getInstance().getConfigurationService().getPropertyAsType("String_Node_Str" + bi.getName(),DSpaceServicesFactory.getInstance().getConfigurationService().getPropertyAsType("String_Node_Str",new Boolean(false)),true);
                  if (!ignoreVariants) {
                    variants=choiceAuthorityService.getVariants(values.get(x));
                  }
                  if (StringUtils.isNotBlank(preferedLabel)) {
                    String nLabel=OrderFormat.makeSortString(preferedLabel,values.get(x).getLanguage(),bi.getDataType());
                    distFValues.add(nLabel + SolrServiceImpl.FILTER_SEPARATOR + preferedLabel+ SolrServiceImpl.AUTHORITY_SEPARATOR+ values.get(x).getAuthority());
                    distValuesForAC.add(preferedLabel);
                  }
                  if (variants != null) {
                    for (                    String var : variants) {
                      String nVal=OrderFormat.makeSortString(var,values.get(x).getLanguage(),bi.getDataType());
                      distFValues.add(nVal + SolrServiceImpl.FILTER_SEPARATOR + var+ SolrServiceImpl.AUTHORITY_SEPARATOR+ values.get(x).getAuthority());
                      distValuesForAC.add(var);
                    }
                  }
                }
 else {
                  String nVal=OrderFormat.makeSortString(values.get(x).getValue(),values.get(x).getLanguage(),bi.getDataType());
                  distFValues.add(nVal + SolrServiceImpl.FILTER_SEPARATOR + values.get(x).getValue());
                  distFVal.add(values.get(x).getValue());
                  distValuesForAC.add(values.get(x).getValue());
                }
              }
            }
          }
        }
      }
      for (      String facet : distFValues) {
        document.addField(bi.getDistinctTableName() + "String_Node_Str",facet);
      }
      for (      String facet : distFAuths) {
        document.addField(bi.getDistinctTableName() + "String_Node_Str",facet);
      }
      for (      String facet : distValuesForAC) {
        document.addField(bi.getDistinctTableName() + "String_Node_Str",facet);
      }
      for (      String facet : distFVal) {
        document.addField(bi.getDistinctTableName() + "String_Node_Str",facet);
      }
    }
  }
  try {
    for (    SortOption so : SortOption.getSortOptions()) {
      List<MetadataValue> dcvalue=itemService.getMetadataByMetadataString(item,so.getMetadata());
      if (dcvalue != null && dcvalue.size() > 0) {
        String nValue=OrderFormat.makeSortString(dcvalue.get(0).getValue(),dcvalue.get(0).getLanguage(),so.getType());
        document.addField("String_Node_Str" + so.getNumber() + "String_Node_Str",nValue);
      }
    }
  }
 catch (  SortException e) {
    throw new RuntimeException(e.getMessage(),e);
  }
}