Program: 89450
Project: 89450
Buggy source:
/** 
 * Validate the caveat config and optionally update the cache.
 * @param nodeRef The nodeRef of the config
 * @param updateCache Set to <code>true</code> to update the cache
 */
@SuppressWarnings("String_Node_Str") protected void validateAndReset(NodeRef nodeRef){
  ContentReader cr=contentService.getReader(nodeRef,ContentModel.PROP_CONTENT);
  if (cr != null) {
    String caveatConfigData=cr.getContentString();
    if (caveatConfigData != null) {
      NodeRef existing=getCaveatConfigNode();
      if ((existing != null && (!existing.equals(nodeRef)))) {
        throw new AlfrescoRuntimeException("String_Node_Str" + existing + "String_Node_Str"+ nodeRef+ "String_Node_Str");
      }
      try {
        if (logger.isTraceEnabled()) {
          logger.trace(caveatConfigData);
        }
        Set<QName> models=new HashSet<QName>(1);
        Set<QName> props=new HashSet<QName>(10);
        Set<String> expectedPrefixes=new HashSet<String>(10);
        if (caveatModelQNames.size() > 0) {
          models.addAll(caveatModelQNames);
        }
 else {
          models.addAll(dictionaryService.getAllModels());
        }
        if (logger.isTraceEnabled()) {
          logger.trace("String_Node_Str" + models);
        }
        for (        QName model : models) {
          props.addAll(dictionaryService.getProperties(model,DATATYPE_TEXT));
          expectedPrefixes.addAll(namespaceService.getPrefixes(model.getNamespaceURI()));
        }
        if (props.size() == 0) {
          logger.warn("String_Node_Str");
        }
 else {
          if (logger.isTraceEnabled()) {
            logger.trace("String_Node_Str" + props);
          }
        }
        Map<String,Object> caveatConfigMap=JSONtoFmModel.convertJSONObjectToMap(caveatConfigData);
        for (        Map.Entry<String,Object> conEntry : caveatConfigMap.entrySet()) {
          String conStr=conEntry.getKey();
          QName conQName=QName.resolveToQName(namespaceService,conStr);
          String conPrefix=QName.splitPrefixedQName(conStr)[0];
          boolean prefixFound=false;
          for (          String expectedPrefix : expectedPrefixes) {
            if (conPrefix.equals(expectedPrefix)) {
              prefixFound=true;
            }
          }
          if (!prefixFound) {
            throw new AlfrescoRuntimeException("String_Node_Str" + conPrefix + "String_Node_Str"+ conStr+ "String_Node_Str"+ expectedPrefixes+ "String_Node_Str");
          }
          Map<String,List<String>> caveatMap=(Map<String,List<String>>)conEntry.getValue();
          List<String> allowedValues=null;
          boolean found=false;
          for (          QName propertyName : props) {
            PropertyDefinition propDef=dictionaryService.getProperty(propertyName);
            List<ConstraintDefinition> conDefs=propDef.getConstraints();
            for (            ConstraintDefinition conDef : conDefs) {
              final Constraint con=conDef.getConstraint();
              if (con instanceof RMListOfValuesConstraint) {
                String conName=((RMListOfValuesConstraint)con).getShortName();
                if (conName.equals(conStr)) {
                  allowedValues=AuthenticationUtil.runAs(new RunAsWork<List<String>>(){
                    public List<String> doWork(){
                      return ((RMListOfValuesConstraint)con).getAllowedValues();
                    }
                  }
,AuthenticationUtil.getSystemUserName());
                  found=true;
                  break;
                }
              }
            }
          }
          if (!found) {
          }
          if (allowedValues != null) {
            if (logger.isInfoEnabled()) {
              logger.info("String_Node_Str" + conQName);
            }
            for (            Map.Entry<String,List<String>> caveatEntry : caveatMap.entrySet()) {
              String authorityName=caveatEntry.getKey();
              List<String> caveatList=caveatEntry.getValue();
              if ((!authorityService.authorityExists(authorityName) && !personService.personExists(authorityName))) {
                String msg="String_Node_Str" + authorityName + "String_Node_Str"+ conStr+ "String_Node_Str";
                logger.warn(msg);
              }
              for (              String value : caveatList) {
                if (!allowedValues.contains(value)) {
                  String msg="String_Node_Str" + value + "String_Node_Str"+ authorityName+ "String_Node_Str"+ conStr+ "String_Node_Str";
                  logger.warn(msg);
                }
              }
            }
          }
        }
        try {
          writeLock.lock();
          caveatConfig.getKeys().retainAll(caveatConfigMap.keySet());
          for (          Map.Entry<String,Object> conEntry : caveatConfigMap.entrySet()) {
            String conStr=conEntry.getKey();
            Map<String,List<String>> caveatMap=(Map<String,List<String>>)conEntry.getValue();
            Map<String,List<String>> cacheValue=caveatConfig.get(conStr);
            if (cacheValue == null || !cacheValue.equals(caveatMap)) {
              caveatConfig.put(conStr,caveatMap);
            }
          }
        }
  finally {
          writeLock.unlock();
        }
      }
 catch (      JSONException e) {
        throw new AlfrescoRuntimeException("String_Node_Str" + e);
      }
    }
  }
}

Fixed version (ground truth):
/** 
 * Validate the caveat config and optionally update the cache.
 * @param nodeRef The nodeRef of the config
 * @param updateCache Set to <code>true</code> to update the cache
 */
@SuppressWarnings("String_Node_Str") protected void validateAndReset(NodeRef nodeRef){
  ContentReader cr=contentService.getReader(nodeRef,ContentModel.PROP_CONTENT);
  if (cr != null) {
    String caveatConfigData=cr.getContentString();
    if (caveatConfigData != null) {
      NodeRef existing=getCaveatConfigNode();
      if ((existing != null && (!existing.equals(nodeRef)))) {
        throw new AlfrescoRuntimeException("String_Node_Str" + existing + "String_Node_Str"+ nodeRef+ "String_Node_Str");
      }
      try {
        if (logger.isTraceEnabled()) {
          logger.trace(caveatConfigData);
        }
        Set<QName> models=new HashSet<QName>(1);
        Set<QName> props=new HashSet<QName>(10);
        Set<String> expectedPrefixes=new HashSet<String>(10);
        if (caveatModelQNames.size() > 0) {
          models.addAll(caveatModelQNames);
        }
 else {
          models.addAll(dictionaryService.getAllModels());
        }
        if (logger.isTraceEnabled()) {
          logger.trace("String_Node_Str" + models);
        }
        for (        QName model : models) {
          props.addAll(dictionaryService.getProperties(model,DATATYPE_TEXT));
          expectedPrefixes.addAll(namespaceService.getPrefixes(model.getNamespaceURI()));
        }
        if (props.size() == 0) {
          logger.warn("String_Node_Str");
        }
 else {
          if (logger.isTraceEnabled()) {
            logger.trace("String_Node_Str" + props);
          }
        }
        Map<String,Object> caveatConfigMap=JSONtoFmModel.convertJSONObjectToMap(caveatConfigData);
        for (        Map.Entry<String,Object> conEntry : caveatConfigMap.entrySet()) {
          String conStr=conEntry.getKey();
          QName conQName=QName.resolveToQName(namespaceService,conStr);
          String conPrefix=QName.splitPrefixedQName(conStr)[0];
          boolean prefixFound=false;
          for (          String expectedPrefix : expectedPrefixes) {
            if (conPrefix.equals(expectedPrefix)) {
              prefixFound=true;
            }
          }
          if (!prefixFound) {
            throw new AlfrescoRuntimeException("String_Node_Str" + conPrefix + "String_Node_Str"+ conStr+ "String_Node_Str"+ expectedPrefixes+ "String_Node_Str");
          }
          Map<String,List<String>> caveatMap=(Map<String,List<String>>)conEntry.getValue();
          List<String> allowedValues=null;
          @SuppressWarnings("String_Node_Str") boolean found=false;
          for (          QName propertyName : props) {
            PropertyDefinition propDef=dictionaryService.getProperty(propertyName);
            List<ConstraintDefinition> conDefs=propDef.getConstraints();
            for (            ConstraintDefinition conDef : conDefs) {
              final Constraint con=conDef.getConstraint();
              if (con instanceof RMListOfValuesConstraint) {
                String conName=((RMListOfValuesConstraint)con).getShortName();
                if (conName.equals(conStr)) {
                  allowedValues=AuthenticationUtil.runAs(new RunAsWork<List<String>>(){
                    public List<String> doWork(){
                      return ((RMListOfValuesConstraint)con).getAllowedValues();
                    }
                  }
,AuthenticationUtil.getSystemUserName());
                  found=true;
                  break;
                }
              }
            }
          }
          if (allowedValues != null) {
            if (logger.isInfoEnabled()) {
              logger.info("String_Node_Str" + conQName);
            }
            for (            Map.Entry<String,List<String>> caveatEntry : caveatMap.entrySet()) {
              String authorityName=caveatEntry.getKey();
              List<String> caveatList=caveatEntry.getValue();
              if ((!authorityService.authorityExists(authorityName) && !personService.personExists(authorityName))) {
                String msg="String_Node_Str" + authorityName + "String_Node_Str"+ conStr+ "String_Node_Str";
                logger.warn(msg);
              }
              for (              String value : caveatList) {
                if (!allowedValues.contains(value)) {
                  String msg="String_Node_Str" + value + "String_Node_Str"+ authorityName+ "String_Node_Str"+ conStr+ "String_Node_Str";
                  logger.warn(msg);
                }
              }
            }
          }
        }
        try {
          writeLock.lock();
          caveatConfig.getKeys().retainAll(caveatConfigMap.keySet());
          for (          Map.Entry<String,Object> conEntry : caveatConfigMap.entrySet()) {
            String conStr=conEntry.getKey();
            Map<String,List<String>> caveatMap=(Map<String,List<String>>)conEntry.getValue();
            Map<String,List<String>> cacheValue=caveatConfig.get(conStr);
            if (cacheValue == null || !cacheValue.equals(caveatMap)) {
              caveatConfig.put(conStr,caveatMap);
            }
          }
        }
  finally {
          writeLock.unlock();
        }
      }
 catch (      JSONException e) {
        throw new AlfrescoRuntimeException("String_Node_Str" + e);
      }
    }
  }
}