Program: 29081
Project: 29081
Buggy source:
/** 
 * checks whether duplicate resource exists or resource is already created but not resource-ref or resource-ref already exists.
 * @param resources resources
 * @param jndiName resource-name
 * @param validateResourceRef whether to validate resource-ref
 * @param target target instance/cluster/domain
 * @param resourceTypeToValidate type of resource
 * @return ResourceStatus indicating Success or Failure
 */
public ResourceStatus validateBindableResourceForDuplicates(Resources resources,String jndiName,boolean validateResourceRef,String target,Class<? extends BindableResource> resourceTypeToValidate){
  BindableResource duplicateResource=ResourceUtil.getBindableResourceByName(resources,jndiName);
  if (duplicateResource != null) {
    String msg;
    if (validateResourceRef && (getResourceByClass(duplicateResource).equals(resourceTypeToValidate))) {
      if (target.equals("String_Node_Str")) {
        msg=localStrings.getLocalString("String_Node_Str","String_Node_Str",getResourceTypeName(duplicateResource),jndiName);
      }
 else       if (habitat.<org.glassfish.resourcebase.resources.admin.cli.ResourceUtil>getService(ResourceUtil.class).getTargetsReferringResourceRef(jndiName).contains(target)) {
        msg=localStrings.getLocalString("String_Node_Str","String_Node_Str",getResourceTypeName(duplicateResource),jndiName,target);
      }
 else {
        msg=localStrings.getLocalString("String_Node_Str","String_Node_Str" + "String_Node_Str" + "String_Node_Str",getResourceTypeName(duplicateResource),jndiName,target);
      }
    }
 else {
      msg=localStrings.getLocalString("String_Node_Str","String_Node_Str",getResourceTypeName(duplicateResource),jndiName);
    }
    return new ResourceStatus(ResourceStatus.FAILURE,msg,true);
  }
 else {
    return new ResourceStatus(ResourceStatus.SUCCESS,"String_Node_Str");
  }
}

Fixed version (ground truth):
/** 
 * checks whether duplicate resource exists or resource is already created but not resource-ref or resource-ref already exists.
 * @param resources resources
 * @param jndiName resource-name
 * @param validateResourceRef whether to validate resource-ref
 * @param target target instance/cluster/domain
 * @param resourceTypeToValidate type of resource
 * @return ResourceStatus indicating Success or Failure
 */
public ResourceStatus validateBindableResourceForDuplicates(Resources resources,String jndiName,boolean validateResourceRef,String target,Class<? extends BindableResource> resourceTypeToValidate){
  BindableResource duplicateResource=ResourceUtil.getBindableResourceByName(resources,jndiName);
  if (duplicateResource != null) {
    String msg;
    if (validateResourceRef && (getResourceByClass(duplicateResource).equals(resourceTypeToValidate))) {
      if (target.equals("String_Node_Str")) {
        msg=localStrings.getLocalString("String_Node_Str","String_Node_Str",getResourceTypeName(duplicateResource),jndiName);
      }
 else       if (habitat.<org.glassfish.resourcebase.resources.admin.cli.ResourceUtil>getService(org.glassfish.resourcebase.resources.admin.cli.ResourceUtil.class).getTargetsReferringResourceRef(jndiName).contains(target)) {
        msg=localStrings.getLocalString("String_Node_Str","String_Node_Str",getResourceTypeName(duplicateResource),jndiName,target);
      }
 else {
        msg=localStrings.getLocalString("String_Node_Str","String_Node_Str" + "String_Node_Str" + "String_Node_Str",getResourceTypeName(duplicateResource),jndiName,target);
      }
    }
 else {
      msg=localStrings.getLocalString("String_Node_Str","String_Node_Str",getResourceTypeName(duplicateResource),jndiName);
    }
    return new ResourceStatus(ResourceStatus.FAILURE,msg,true);
  }
 else {
    return new ResourceStatus(ResourceStatus.SUCCESS,"String_Node_Str");
  }
}