Program: 23265
Project: 23265
Buggy source:
/** 
 * @param element - the candidate that might be in the slice
 * @param path - for reporting any errors. the XPath for the element
 * @param slice - the definition of how slicing is determined
 * @param ed - the slice for which to test membership
 * @param errors 
 * @param stack 
 * @return
 * @throws DefinitionException 
 * @throws DefinitionException 
 * @throws IOException 
 * @throws FHIRException
 */
private boolean sliceMatches(Object appContext,Element element,String path,ElementDefinition slice,ElementDefinition ed,StructureDefinition profile,List<ValidationMessage> errors,NodeStack stack) throws DefinitionException, FHIRException, IOException {
  if (!slice.getSlicing().hasDiscriminator())   return false;
  ExpressionNode n=(ExpressionNode)ed.getUserData("String_Node_Str");
  if (n == null) {
    long t=System.nanoTime();
    String expression="String_Node_Str";
    for (    ElementDefinitionSlicingDiscriminatorComponent s : slice.getSlicing().getDiscriminator()) {
      String discriminator=s.getPath();
      if (s.getType() == DiscriminatorType.PROFILE)       throw new FHIRException("String_Node_Str" + discriminator);
      ElementDefinition criteriaElement=getCriteriaForDiscriminator(path,ed,discriminator,profile);
      if (s.getType() == DiscriminatorType.TYPE) {
        String type=null;
        if (!criteriaElement.getPath().contains("String_Node_Str") && discriminator.contains("String_Node_Str")) {
          discriminator=discriminator.substring(0,discriminator.indexOf('['));
          String lastNode=tail(discriminator);
          type=tail(criteriaElement.getPath()).substring(lastNode.length());
          type=type.substring(0,1).toLowerCase() + type.substring(1);
        }
 else         if (!criteriaElement.hasType() || criteriaElement.getType().size() == 1) {
          if (discriminator.contains("String_Node_Str"))           discriminator=discriminator.substring(0,discriminator.indexOf('['));
          type=criteriaElement.getType().get(0).getCode();
        }
        if (type == null)         throw new DefinitionException("String_Node_Str" + discriminator + "String_Node_Str"+ slice.getSliceName()+ "String_Node_Str");
        if (discriminator.isEmpty())         expression=expression + "String_Node_Str" + type;
 else         expression=expression + "String_Node_Str" + discriminator+ "String_Node_Str"+ type;
      }
 else       if (criteriaElement.hasFixed()) {
        expression=expression + "String_Node_Str" + discriminator+ "String_Node_Str";
        Type fixed=criteriaElement.getFixed();
        if (fixed instanceof StringType) {
          Gson gson=new Gson();
          String json=gson.toJson((StringType)fixed);
          String escapedString=json.substring(json.indexOf("String_Node_Str") + 2);
          escapedString=escapedString.substring(0,escapedString.indexOf("String_Node_Str") - 1);
          expression=expression + "String_Node_Str" + escapedString+ "String_Node_Str";
        }
 else         if (fixed instanceof UriType) {
          expression=expression + "String_Node_Str" + ((UriType)fixed).asStringValue()+ "String_Node_Str";
        }
 else         if (fixed instanceof IntegerType) {
          expression=expression + ((IntegerType)fixed).asStringValue();
        }
 else         if (fixed instanceof DecimalType) {
          expression=expression + ((IntegerType)fixed).asStringValue();
        }
 else         if (fixed instanceof BooleanType) {
          expression=expression + ((BooleanType)fixed).asStringValue();
        }
 else         throw new DefinitionException("String_Node_Str" + discriminator + "String_Node_Str"+ slice.getSliceName()+ "String_Node_Str"+ fixed.getClass().getName());
      }
 else       if (criteriaElement.hasBinding() && criteriaElement.getBinding().hasStrength() && criteriaElement.getBinding().getStrength().equals(BindingStrength.REQUIRED)&& criteriaElement.getBinding().getValueSetReference() != null) {
        expression=expression + "String_Node_Str" + discriminator+ "String_Node_Str"+ criteriaElement.getBinding().getValueSetReference().getReference()+ "String_Node_Str";
      }
 else       if (criteriaElement.hasMin() && criteriaElement.getMin() > 0) {
        expression=expression + "String_Node_Str" + discriminator+ "String_Node_Str";
      }
 else       if (criteriaElement.hasMax() && criteriaElement.getMax().equals("String_Node_Str")) {
        expression=expression + "String_Node_Str" + discriminator+ "String_Node_Str";
      }
 else {
        throw new DefinitionException("String_Node_Str" + discriminator + "String_Node_Str"+ slice.getSliceName()+ "String_Node_Str");
      }
    }
    try {
      n=fpe.parse(expression);
    }
 catch (    FHIRLexerException e) {
      throw new FHIRException("String_Node_Str" + expression + "String_Node_Str"+ profile.getUrl()+ "String_Node_Str"+ path+ "String_Node_Str"+ e.getMessage());
    }
    fpeTime=fpeTime + (System.nanoTime() - t);
    ed.setUserData("String_Node_Str",n);
  }
  String msg;
  boolean ok;
  try {
    long t=System.nanoTime();
    ok=fpe.evaluateToBoolean(null,element,n);
    fpeTime=fpeTime + (System.nanoTime() - t);
    msg=fpe.forLog();
  }
 catch (  Exception ex) {
    throw new FHIRException("String_Node_Str" + profile.getUrl() + "String_Node_Str"+ path+ "String_Node_Str"+ ex.getMessage());
  }
  return ok;
}

Fixed version (ground truth):
/** 
 * @param element - the candidate that might be in the slice
 * @param path - for reporting any errors. the XPath for the element
 * @param slice - the definition of how slicing is determined
 * @param ed - the slice for which to test membership
 * @param errors 
 * @param stack 
 * @return
 * @throws DefinitionException 
 * @throws DefinitionException 
 * @throws IOException 
 * @throws FHIRException
 */
private boolean sliceMatches(Object appContext,Element element,String path,ElementDefinition slicer,ElementDefinition ed,StructureDefinition profile,List<ValidationMessage> errors,NodeStack stack) throws DefinitionException, FHIRException, IOException {
  if (!slicer.getSlicing().hasDiscriminator())   return false;
  ExpressionNode n=(ExpressionNode)ed.getUserData("String_Node_Str");
  if (n == null) {
    long t=System.nanoTime();
    String expression="String_Node_Str";
    for (    ElementDefinitionSlicingDiscriminatorComponent s : slicer.getSlicing().getDiscriminator()) {
      String discriminator=s.getPath();
      if (s.getType() == DiscriminatorType.PROFILE)       throw new FHIRException("String_Node_Str" + discriminator);
      ElementDefinition criteriaElement=getCriteriaForDiscriminator(path,ed,discriminator,profile);
      if (s.getType() == DiscriminatorType.TYPE) {
        String type=null;
        if (!criteriaElement.getPath().contains("String_Node_Str") && discriminator.contains("String_Node_Str")) {
          discriminator=discriminator.substring(0,discriminator.indexOf('['));
          String lastNode=tail(discriminator);
          type=tail(criteriaElement.getPath()).substring(lastNode.length());
          type=type.substring(0,1).toLowerCase() + type.substring(1);
        }
 else         if (!criteriaElement.hasType() || criteriaElement.getType().size() == 1) {
          if (discriminator.contains("String_Node_Str"))           discriminator=discriminator.substring(0,discriminator.indexOf('['));
          type=criteriaElement.getType().get(0).getCode();
        }
        if (type == null)         throw new DefinitionException("String_Node_Str" + discriminator + "String_Node_Str"+ slicer.getSliceName()+ "String_Node_Str");
        if (discriminator.isEmpty())         expression=expression + "String_Node_Str" + type;
 else         expression=expression + "String_Node_Str" + discriminator+ "String_Node_Str"+ type;
      }
 else       if (criteriaElement.hasFixed()) {
        expression=expression + "String_Node_Str" + discriminator+ "String_Node_Str";
        Type fixed=criteriaElement.getFixed();
        if (fixed instanceof StringType) {
          Gson gson=new Gson();
          String json=gson.toJson((StringType)fixed);
          String escapedString=json.substring(json.indexOf("String_Node_Str") + 2);
          escapedString=escapedString.substring(0,escapedString.indexOf("String_Node_Str") - 1);
          expression=expression + "String_Node_Str" + escapedString+ "String_Node_Str";
        }
 else         if (fixed instanceof UriType) {
          expression=expression + "String_Node_Str" + ((UriType)fixed).asStringValue()+ "String_Node_Str";
        }
 else         if (fixed instanceof IntegerType) {
          expression=expression + ((IntegerType)fixed).asStringValue();
        }
 else         if (fixed instanceof DecimalType) {
          expression=expression + ((IntegerType)fixed).asStringValue();
        }
 else         if (fixed instanceof BooleanType) {
          expression=expression + ((BooleanType)fixed).asStringValue();
        }
 else         throw new DefinitionException("String_Node_Str" + discriminator + "String_Node_Str"+ slicer.getSliceName()+ "String_Node_Str"+ fixed.getClass().getName());
      }
 else       if (criteriaElement.hasBinding() && criteriaElement.getBinding().hasStrength() && criteriaElement.getBinding().getStrength().equals(BindingStrength.REQUIRED)&& criteriaElement.getBinding().getValueSetReference() != null) {
        expression=expression + "String_Node_Str" + discriminator+ "String_Node_Str"+ criteriaElement.getBinding().getValueSetReference().getReference()+ "String_Node_Str";
      }
 else       if (criteriaElement.hasMin() && criteriaElement.getMin() > 0) {
        expression=expression + "String_Node_Str" + discriminator+ "String_Node_Str";
      }
 else       if (criteriaElement.hasMax() && criteriaElement.getMax().equals("String_Node_Str")) {
        expression=expression + "String_Node_Str" + discriminator+ "String_Node_Str";
      }
 else {
        throw new DefinitionException("String_Node_Str" + discriminator + "String_Node_Str"+ slicer.getSliceName()+ "String_Node_Str");
      }
    }
    try {
      n=fpe.parse(expression);
    }
 catch (    FHIRLexerException e) {
      throw new FHIRException("String_Node_Str" + expression + "String_Node_Str"+ profile.getUrl()+ "String_Node_Str"+ path+ "String_Node_Str"+ e.getMessage());
    }
    fpeTime=fpeTime + (System.nanoTime() - t);
    ed.setUserData("String_Node_Str",n);
  }
  String msg;
  boolean ok;
  try {
    long t=System.nanoTime();
    ok=fpe.evaluateToBoolean(null,element,n);
    fpeTime=fpeTime + (System.nanoTime() - t);
    msg=fpe.forLog();
  }
 catch (  Exception ex) {
    throw new FHIRException("String_Node_Str" + profile.getUrl() + "String_Node_Str"+ path+ "String_Node_Str"+ ex.getMessage());
  }
  return ok;
}