nus-yam/ex-repair huggingface dataset:
Program: 11063
Project: 11063
Buggy source:
private void translateToELM(ANTLRInputStream is,Options... options){
  cqlLexer lexer=new cqlLexer(is);
  CommonTokenStream tokens=new CommonTokenStream(lexer);
  cqlParser parser=new cqlParser(tokens);
  parser.setBuildParseTree(true);
  errors=new ArrayList<>();
  Cql2ElmVisitor visitor=new Cql2ElmVisitor(libraryManager);
  parser.addErrorListener(new CqlErrorListener(visitor));
  ParseTree tree=parser.logic();
  CqlPreprocessorVisitor preprocessor=new CqlPreprocessorVisitor();
  preprocessor.visit(tree);
  visitor.setLibraryInfo(preprocessor.getLibraryInfo());
  visitor.setTokenStream(tokens);
  List<Options> optionList=Arrays.asList(options);
  if (optionList.contains(Options.EnableDateRangeOptimization)) {
    visitor.enableDateRangeOptimization();
  }
  if (optionList.contains(Options.EnableAnnotations)) {
    visitor.enableAnnotations();
  }
  visitResult=visitor.visit(tree);
  library=visitor.getLibrary();
  translatedLibrary=visitor.getTranslatedLibrary();
  retrieves=visitor.getRetrieves();
  errors.addAll(visitor.getErrors());
}

Fixed version (ground truth):
private void translateToELM(ANTLRInputStream is,Options... options){
  cqlLexer lexer=new cqlLexer(is);
  CommonTokenStream tokens=new CommonTokenStream(lexer);
  cqlParser parser=new cqlParser(tokens);
  parser.setBuildParseTree(true);
  errors=new ArrayList<>();
  Cql2ElmVisitor visitor=new Cql2ElmVisitor(libraryManager);
  List<Options> optionList=Arrays.asList(options);
  if (optionList.contains(Options.EnableDateRangeOptimization)) {
    visitor.enableDateRangeOptimization();
  }
  if (optionList.contains(Options.EnableAnnotations)) {
    visitor.enableAnnotations();
  }
  if (optionList.contains(Options.EnableDetailedErrors)) {
    visitor.enableDetailedErrors();
  }
  parser.removeErrorListeners();
  parser.addErrorListener(new CqlErrorListener(visitor));
  ParseTree tree=parser.logic();
  CqlPreprocessorVisitor preprocessor=new CqlPreprocessorVisitor();
  preprocessor.visit(tree);
  visitor.setLibraryInfo(preprocessor.getLibraryInfo());
  visitor.setTokenStream(tokens);
  visitResult=visitor.visit(tree);
  library=visitor.getLibrary();
  translatedLibrary=visitor.getTranslatedLibrary();
  retrieves=visitor.getRetrieves();
  errors.addAll(visitor.getErrors());
}
Program: 11066
Project: 11066
Buggy source:
public static void verifyCast(DataType targetType,DataType sourceType){
  if (!subTypeOf(targetType,sourceType)) {
    throw new IllegalArgumentException(String.format("String_Node_Str",sourceType != null ? sourceType.toString() : "String_Node_Str",targetType != null ? targetType.toString() : "String_Node_Str"));
  }
}

Fixed version (ground truth):
public static void verifyCast(DataType targetType,DataType sourceType){
  if (!subTypeOf(targetType,sourceType)) {
    throw new IllegalArgumentException(String.format("String_Node_Str",sourceType != null ? sourceType.toLabel() : "String_Node_Str",targetType != null ? targetType.toLabel() : "String_Node_Str"));
  }
}
Program: 11067
Project: 11067
Buggy source:
public static void verifyType(DataType actualType,DataType expectedType){
  if (!subTypeOf(actualType,expectedType)) {
    throw new IllegalArgumentException(String.format("String_Node_Str",expectedType != null ? expectedType.toString() : "String_Node_Str",actualType != null ? actualType.toString() : "String_Node_Str"));
  }
}

Fixed version (ground truth):
public static void verifyType(DataType actualType,DataType expectedType){
  if (!subTypeOf(actualType,expectedType)) {
    throw new IllegalArgumentException(String.format("String_Node_Str",expectedType != null ? expectedType.toLabel() : "String_Node_Str",actualType != null ? actualType.toLabel() : "String_Node_Str"));
  }
}
Program: 11068
Project: 11068
Buggy source:
@Override public Object visitFunctionDefinition(@NotNull cqlParser.FunctionDefinitionContext ctx){
  FunctionDef fun=of.createFunctionDef().withAccessLevel(parseAccessModifier(ctx.accessModifier())).withName(parseString(ctx.identifier()));
  if (ctx.operandDefinition() != null) {
    for (    cqlParser.OperandDefinitionContext opdef : ctx.operandDefinition()) {
      TypeSpecifier typeSpecifier=parseTypeSpecifier(opdef.typeSpecifier());
      fun.getOperand().add((OperandDef)of.createOperandDef().withName(parseString(opdef.identifier())).withOperandTypeSpecifier(typeSpecifier).withResultType(typeSpecifier.getResultType()));
    }
  }
  currentFunctionDef=fun;
  pushExpressionContext(currentContext);
  try {
    fun.setExpression(parseExpression(ctx.functionBody()));
  }
  finally {
    currentFunctionDef=null;
    popExpressionContext();
  }
  fun.setContext(currentContext);
  fun.setResultType(fun.getExpression().getResultType());
  addToLibrary(fun);
  return fun;
}

Fixed version (ground truth):
@Override public Object visitFunctionDefinition(@NotNull cqlParser.FunctionDefinitionContext ctx){
  FunctionDef result=(FunctionDef)internalVisitFunctionDefinition(ctx);
  Operator operator=Operator.fromFunctionDef(result);
  Set<Signature> definedSignatures=definedFunctionDefinitions.get(operator.getName());
  if (definedSignatures == null) {
    definedSignatures=new HashSet<>();
    definedFunctionDefinitions.put(operator.getName(),definedSignatures);
  }
  if (definedSignatures.contains(operator.getSignature())) {
    throw new IllegalArgumentException(String.format("String_Node_Str",operator.getName()));
  }
  definedSignatures.add(operator.getSignature());
  return result;
}
Program: 11069
Project: 11069
Buggy source:
@Override public SortByItem visitSortByItem(@NotNull cqlParser.SortByItemContext ctx){
  Expression sortExpression=parseExpression(ctx.expressionTerm());
  if (sortExpression instanceof IdentifierRef) {
    return of.createByColumn().withPath(((IdentifierRef)sortExpression).getName()).withDirection(parseSortDirection(ctx.sortDirection()));
  }
  return of.createByExpression().withExpression(sortExpression).withDirection(parseSortDirection(ctx.sortDirection()));
}

Fixed version (ground truth):
@Override public SortByItem visitSortByItem(@NotNull cqlParser.SortByItemContext ctx){
  Expression sortExpression=parseExpression(ctx.expressionTerm());
  if (sortExpression instanceof IdentifierRef) {
    return (SortByItem)of.createByColumn().withPath(((IdentifierRef)sortExpression).getName()).withDirection(parseSortDirection(ctx.sortDirection())).withResultType(sortExpression.getResultType());
  }
  return (SortByItem)of.createByExpression().withExpression(sortExpression).withDirection(parseSortDirection(ctx.sortDirection())).withResultType(sortExpression.getResultType());
}
Program: 11072
Project: 11072
Buggy source:
private String parseString(ParseTree pt){
  return pt == null ? null : (String)visit(pt);
}

Fixed version (ground truth):
private String parseString(ParseTree pt){
  return StringEscapeUtils.unescapeCql(pt == null ? null : (String)visit(pt));
}
Program: 11073
Project: 11073
Buggy source:
protected Expression resolveFunction(String libraryName,String operatorName,Invocation invocation){
  boolean checkForward=libraryName == null || libraryName.equals("String_Node_Str") || libraryName.equals(this.libraryInfo.getLibraryName());
  Expression result=resolveCall(libraryName,operatorName,invocation,!checkForward);
  if (result == null) {
    Iterable<FunctionDefinitionInfo> functionInfos=libraryInfo.resolveFunctionReference(operatorName);
    for (    FunctionDefinitionInfo functionInfo : functionInfos) {
      visitFunctionDefinition(functionInfo.getDefinition());
    }
    result=resolveCall(libraryName,operatorName,invocation,true);
  }
  return result;
}

Fixed version (ground truth):
protected Expression resolveFunction(String libraryName,String operatorName,Invocation invocation){
  boolean checkForward=libraryName == null || libraryName.equals("String_Node_Str") || libraryName.equals(this.libraryInfo.getLibraryName());
  Expression result=resolveCall(libraryName,operatorName,invocation,!checkForward);
  if (result == null) {
    Iterable<FunctionDefinitionInfo> functionInfos=libraryInfo.resolveFunctionReference(operatorName);
    if (functionInfos != null) {
      for (      FunctionDefinitionInfo functionInfo : functionInfos) {
        internalVisitFunctionDefinition(functionInfo.getDefinition());
      }
    }
    result=resolveCall(libraryName,operatorName,invocation,true);
  }
  return result;
}
Program: 11074
Project: 11074
Buggy source:
@Override public ExpressionDef visitExpressionDefinition(@NotNull cqlParser.ExpressionDefinitionContext ctx){
  String identifier=parseString(ctx.identifier());
  ExpressionDef def=translatedLibrary.resolveExpressionRef(identifier);
  if (def == null) {
    pushExpressionDefinition(identifier);
    pushExpressionContext(currentContext);
    try {
      def=of.createExpressionDef().withAccessLevel(parseAccessModifier(ctx.accessModifier())).withName(identifier).withContext(currentContext).withExpression((Expression)visit(ctx.expression()));
      def.setResultType(def.getExpression().getResultType());
      addToLibrary(def);
    }
  finally {
      popExpressionDefinition();
      popExpressionContext();
    }
  }
  return def;
}

Fixed version (ground truth):
@Override public ExpressionDef visitExpressionDefinition(@NotNull cqlParser.ExpressionDefinitionContext ctx){
  ExpressionDef expressionDef=internalVisitExpressionDefinition(ctx);
  if (definedExpressionDefinitions.contains(expressionDef.getName())) {
    throw new IllegalArgumentException(String.format("String_Node_Str",expressionDef.getName()));
  }
  definedExpressionDefinitions.add(expressionDef.getName());
  return expressionDef;
}
Program: 11075
Project: 11075
Buggy source:
public Operator(String name,Signature signature,DataType resultType){
  if (name == null || name.equals("String_Node_Str")) {
    throw new IllegalArgumentException("String_Node_Str");
  }
  if (signature == null) {
    throw new IllegalArgumentException("String_Node_Str");
  }
  if (resultType == null) {
    throw new IllegalArgumentException("String_Node_Str");
  }
  this.name=name;
  this.signature=signature;
  this.resultType=resultType;
}

Fixed version (ground truth):
public Operator(String name,Signature signature,DataType resultType){
  if (name == null || name.equals("String_Node_Str")) {
    throw new IllegalArgumentException("String_Node_Str");
  }
  if (signature == null) {
    throw new IllegalArgumentException("String_Node_Str");
  }
  this.name=name;
  this.signature=signature;
  this.resultType=resultType;
}
Program: 11076
Project: 11076
Buggy source:
public boolean contains(Operator operator){
  return signatures.containsKey(operator.getSignature());
}

Fixed version (ground truth):
public boolean contains(Operator operator){
  boolean result=signatures.containsKey(operator.getSignature());
  if (!result) {
    for (    SignatureNode n : signatures.values()) {
      result=n.subSignatures.contains(operator);
      if (result) {
        break;
      }
    }
  }
  return result;
}
Program: 11078
Project: 11078
Buggy source:
private Operator instantiate(Signature signature,OperatorMap operatorMap,ConversionMap conversionMap){
  List<Operator> instantiations=new ArrayList<Operator>();
  int lowestConversionScore=Integer.MAX_VALUE;
  Operator instantiation=null;
  for (  GenericOperator genericOperator : genericOperators.values()) {
    InstantiationResult instantiationResult=genericOperator.instantiate(signature,operatorMap,conversionMap);
    if (instantiationResult.getOperator() != null) {
      if (instantiationResult.getConversionScore() <= lowestConversionScore) {
        if (instantiation == null) {
          instantiation=instantiationResult.getOperator();
          lowestConversionScore=instantiationResult.getConversionScore();
        }
 else {
          throw new IllegalArgumentException(String.format("String_Node_Str",this.name,instantiation.getSignature().toString(),instantiationResult.getOperator().getSignature().toString()));
        }
      }
    }
  }
  return instantiation;
}

Fixed version (ground truth):
private Operator instantiate(Signature signature,OperatorMap operatorMap,ConversionMap conversionMap){
  List<Operator> instantiations=new ArrayList<Operator>();
  int lowestConversionScore=Integer.MAX_VALUE;
  Operator instantiation=null;
  for (  GenericOperator genericOperator : genericOperators.values()) {
    InstantiationResult instantiationResult=genericOperator.instantiate(signature,operatorMap,conversionMap);
    if (instantiationResult.getOperator() != null) {
      if (instantiationResult.getConversionScore() <= lowestConversionScore) {
        if (instantiation == null || instantiationResult.getConversionScore() < lowestConversionScore) {
          instantiation=instantiationResult.getOperator();
          lowestConversionScore=instantiationResult.getConversionScore();
        }
 else {
          throw new IllegalArgumentException(String.format("String_Node_Str",this.name,instantiation.getSignature().toString(),instantiationResult.getOperator().getSignature().toString()));
        }
      }
    }
  }
  return instantiation;
}
Program: 11079
Project: 11079
Buggy source:
@Override public Object visitFunctionDefinition(@NotNull cqlParser.FunctionDefinitionContext ctx){
  FunctionDef fun=of.createFunctionDef().withAccessLevel(parseAccessModifier(ctx.accessModifier())).withName(parseString(ctx.identifier()));
  if (ctx.operandDefinition() != null) {
    for (    cqlParser.OperandDefinitionContext opdef : ctx.operandDefinition()) {
      TypeSpecifier typeSpecifier=parseTypeSpecifier(opdef.typeSpecifier());
      fun.getOperand().add((OperandDef)of.createOperandDef().withName(parseString(opdef.identifier())).withOperandTypeSpecifier(typeSpecifier).withResultType(typeSpecifier.getResultType()));
    }
  }
  currentFunctionDef=fun;
  pushExpressionContext(currentContext);
  try {
    fun.setExpression(parseExpression(ctx.functionBody()));
  }
  finally {
    currentFunctionDef=null;
    popExpressionContext();
  }
  fun.setContext(currentContext);
  fun.setResultType(fun.getExpression().getResultType());
  addToLibrary(fun);
  return fun;
}

Fixed version (ground truth):
@Override public Object visitFunctionDefinition(@NotNull cqlParser.FunctionDefinitionContext ctx){
  FunctionDef result=(FunctionDef)internalVisitFunctionDefinition(ctx);
  Operator operator=Operator.fromFunctionDef(result);
  Set<Signature> definedSignatures=definedFunctionDefinitions.get(operator.getName());
  if (definedSignatures == null) {
    definedSignatures=new HashSet<>();
    definedFunctionDefinitions.put(operator.getName(),definedSignatures);
  }
  if (definedSignatures.contains(operator.getSignature())) {
    throw new IllegalArgumentException(String.format("String_Node_Str",operator.getName()));
  }
  definedSignatures.add(operator.getSignature());
  return result;
}
Program: 11080
Project: 11080
Buggy source:
protected Expression resolveFunction(String libraryName,String operatorName,Invocation invocation){
  boolean checkForward=libraryName == null || libraryName.equals("String_Node_Str") || libraryName.equals(this.libraryInfo.getLibraryName());
  Expression result=resolveCall(libraryName,operatorName,invocation,!checkForward);
  if (result == null) {
    Iterable<FunctionDefinitionInfo> functionInfos=libraryInfo.resolveFunctionReference(operatorName);
    for (    FunctionDefinitionInfo functionInfo : functionInfos) {
      visitFunctionDefinition(functionInfo.getDefinition());
    }
    result=resolveCall(libraryName,operatorName,invocation,true);
  }
  return result;
}

Fixed version (ground truth):
protected Expression resolveFunction(String libraryName,String operatorName,Invocation invocation){
  boolean checkForward=libraryName == null || libraryName.equals("String_Node_Str") || libraryName.equals(this.libraryInfo.getLibraryName());
  Expression result=resolveCall(libraryName,operatorName,invocation,!checkForward);
  if (result == null) {
    Iterable<FunctionDefinitionInfo> functionInfos=libraryInfo.resolveFunctionReference(operatorName);
    if (functionInfos != null) {
      for (      FunctionDefinitionInfo functionInfo : functionInfos) {
        internalVisitFunctionDefinition(functionInfo.getDefinition());
      }
    }
    result=resolveCall(libraryName,operatorName,invocation,true);
  }
  return result;
}
Program: 11081
Project: 11081
Buggy source:
public Operator(String name,Signature signature,DataType resultType){
  if (name == null || name.equals("String_Node_Str")) {
    throw new IllegalArgumentException("String_Node_Str");
  }
  if (signature == null) {
    throw new IllegalArgumentException("String_Node_Str");
  }
  if (resultType == null) {
    throw new IllegalArgumentException("String_Node_Str");
  }
  this.name=name;
  this.signature=signature;
  this.resultType=resultType;
}

Fixed version (ground truth):
public Operator(String name,Signature signature,DataType resultType){
  if (name == null || name.equals("String_Node_Str")) {
    throw new IllegalArgumentException("String_Node_Str");
  }
  if (signature == null) {
    throw new IllegalArgumentException("String_Node_Str");
  }
  this.name=name;
  this.signature=signature;
  this.resultType=resultType;
}
Program: 11082
Project: 11082
Buggy source:
public boolean contains(Operator operator){
  return signatures.containsKey(operator.getSignature());
}

Fixed version (ground truth):
public boolean contains(Operator operator){
  boolean result=signatures.containsKey(operator.getSignature());
  if (!result) {
    for (    SignatureNode n : signatures.values()) {
      result=n.subSignatures.contains(operator);
      if (result) {
        break;
      }
    }
  }
  return result;
}
Program: 11084
Project: 11084
Buggy source:
public DataType resolveTypeName(String modelName,String typeName){
  DataType result=resolveLabel(modelName,typeName);
  if (result == null) {
    if (modelName == null || modelName.equals("String_Node_Str")) {
      for (      Model model : models.values()) {
        DataType modelResult=model.resolveTypeName(typeName);
        if (modelResult != null) {
          if (result != null) {
            throw new IllegalArgumentException(String.format("String_Node_Str",typeName,((NamedType)result).getName(),((NamedType)modelResult).getName()));
          }
          result=modelResult;
        }
      }
    }
 else {
      result=getModel(modelName).resolveTypeName(typeName);
    }
  }
  return result;
}

Fixed version (ground truth):
public DataType resolveTypeName(String modelName,String typeName){
  DataType result=resolveLabel(modelName,typeName);
  if (result == null) {
    if (modelName == null || modelName.equals("String_Node_Str")) {
      if (defaultModel != null) {
        DataType modelResult=defaultModel.resolveTypeName(typeName);
        if (modelResult != null) {
          return modelResult;
        }
      }
      for (      Model model : models.values()) {
        DataType modelResult=model.resolveTypeName(typeName);
        if (modelResult != null) {
          if (result != null) {
            throw new IllegalArgumentException(String.format("String_Node_Str",typeName,((NamedType)result).getName(),((NamedType)modelResult).getName()));
          }
          result=modelResult;
        }
      }
    }
 else {
      result=getModel(modelName).resolveTypeName(typeName);
    }
  }
  return result;
}
Program: 11085
Project: 11085
Buggy source:
private Operator instantiate(Signature signature,OperatorMap operatorMap,ConversionMap conversionMap){
  List<Operator> instantiations=new ArrayList<Operator>();
  int lowestConversionScore=Integer.MAX_VALUE;
  Operator instantiation=null;
  for (  GenericOperator genericOperator : genericOperators.values()) {
    InstantiationResult instantiationResult=genericOperator.instantiate(signature,operatorMap,conversionMap);
    if (instantiationResult.getOperator() != null) {
      if (instantiationResult.getConversionScore() <= lowestConversionScore) {
        if (instantiation == null) {
          instantiation=instantiationResult.getOperator();
          lowestConversionScore=instantiationResult.getConversionScore();
        }
 else {
          throw new IllegalArgumentException(String.format("String_Node_Str",this.name,instantiation.getSignature().toString(),instantiationResult.getOperator().getSignature().toString()));
        }
      }
    }
  }
  return instantiation;
}

Fixed version (ground truth):
private Operator instantiate(Signature signature,OperatorMap operatorMap,ConversionMap conversionMap){
  List<Operator> instantiations=new ArrayList<Operator>();
  int lowestConversionScore=Integer.MAX_VALUE;
  Operator instantiation=null;
  for (  GenericOperator genericOperator : genericOperators.values()) {
    InstantiationResult instantiationResult=genericOperator.instantiate(signature,operatorMap,conversionMap);
    if (instantiationResult.getOperator() != null) {
      if (instantiationResult.getConversionScore() <= lowestConversionScore) {
        if (instantiation == null || instantiationResult.getConversionScore() < lowestConversionScore) {
          instantiation=instantiationResult.getOperator();
          lowestConversionScore=instantiationResult.getConversionScore();
        }
 else {
          throw new IllegalArgumentException(String.format("String_Node_Str",this.name,instantiation.getSignature().toString(),instantiationResult.getOperator().getSignature().toString()));
        }
      }
    }
  }
  return instantiation;
}
Program: 11086
Project: 11086
Buggy source:
public boolean contains(Operator operator){
  return signatures.containsKey(operator.getSignature());
}

Fixed version (ground truth):
public boolean contains(Operator operator){
  boolean result=signatures.containsKey(operator.getSignature());
  if (!result) {
    for (    SignatureNode n : signatures.values()) {
      result=n.subSignatures.contains(operator);
      if (result) {
        break;
      }
    }
  }
  return result;
}
Program: 11087
Project: 11087
Buggy source:
public DataType resolveTypeName(String modelName,String typeName){
  DataType result=resolveLabel(modelName,typeName);
  if (result == null) {
    if (modelName == null || modelName.equals("String_Node_Str")) {
      for (      Model model : models.values()) {
        DataType modelResult=model.resolveTypeName(typeName);
        if (modelResult != null) {
          if (result != null) {
            throw new IllegalArgumentException(String.format("String_Node_Str",typeName,((NamedType)result).getName(),((NamedType)modelResult).getName()));
          }
          result=modelResult;
        }
      }
    }
 else {
      result=getModel(modelName).resolveTypeName(typeName);
    }
  }
  return result;
}

Fixed version (ground truth):
public DataType resolveTypeName(String modelName,String typeName){
  DataType result=resolveLabel(modelName,typeName);
  if (result == null) {
    if (modelName == null || modelName.equals("String_Node_Str")) {
      if (defaultModel != null) {
        DataType modelResult=defaultModel.resolveTypeName(typeName);
        if (modelResult != null) {
          return modelResult;
        }
      }
      for (      Model model : models.values()) {
        DataType modelResult=model.resolveTypeName(typeName);
        if (modelResult != null) {
          if (result != null) {
            throw new IllegalArgumentException(String.format("String_Node_Str",typeName,((NamedType)result).getName(),((NamedType)modelResult).getName()));
          }
          result=modelResult;
        }
      }
    }
 else {
      result=getModel(modelName).resolveTypeName(typeName);
    }
  }
  return result;
}
Program: 11089
Project: 11089
Buggy source:
private Operator instantiate(Signature signature,OperatorMap operatorMap,ConversionMap conversionMap){
  List<Operator> instantiations=new ArrayList<Operator>();
  int lowestConversionScore=Integer.MAX_VALUE;
  Operator instantiation=null;
  for (  GenericOperator genericOperator : genericOperators.values()) {
    InstantiationResult instantiationResult=genericOperator.instantiate(signature,operatorMap,conversionMap);
    if (instantiationResult.getOperator() != null) {
      if (instantiationResult.getConversionScore() <= lowestConversionScore) {
        if (instantiation == null) {
          instantiation=instantiationResult.getOperator();
          lowestConversionScore=instantiationResult.getConversionScore();
        }
 else {
          throw new IllegalArgumentException(String.format("String_Node_Str",this.name,instantiation.getSignature().toString(),instantiationResult.getOperator().getSignature().toString()));
        }
      }
    }
  }
  return instantiation;
}

Fixed version (ground truth):
private Operator instantiate(Signature signature,OperatorMap operatorMap,ConversionMap conversionMap){
  List<Operator> instantiations=new ArrayList<Operator>();
  int lowestConversionScore=Integer.MAX_VALUE;
  Operator instantiation=null;
  for (  GenericOperator genericOperator : genericOperators.values()) {
    InstantiationResult instantiationResult=genericOperator.instantiate(signature,operatorMap,conversionMap);
    if (instantiationResult.getOperator() != null) {
      if (instantiationResult.getConversionScore() <= lowestConversionScore) {
        if (instantiation == null || instantiationResult.getConversionScore() < lowestConversionScore) {
          instantiation=instantiationResult.getOperator();
          lowestConversionScore=instantiationResult.getConversionScore();
        }
 else {
          throw new IllegalArgumentException(String.format("String_Node_Str",this.name,instantiation.getSignature().toString(),instantiationResult.getOperator().getSignature().toString()));
        }
      }
    }
  }
  return instantiation;
}
Program: 11090
Project: 11090
Buggy source:
@Override public Expression visitFunction(@NotNull cqlParser.FunctionContext ctx){
  if (!targets.empty()) {
    Expression target=targets.peek();
    if (target instanceof LibraryRef) {
      return resolveFunction(((LibraryRef)target).getLibraryName(),ctx);
    }
    if (target instanceof Expression) {
      throw new IllegalArgumentException("String_Node_Str");
    }
    throw new IllegalArgumentException(String.format("String_Node_Str",target.getClass().getName()));
  }
  return resolveFunction(null,ctx);
}

Fixed version (ground truth):
@Override public Expression visitFunction(@NotNull cqlParser.FunctionContext ctx){
  if (!targets.empty()) {
    Expression target=targets.pop();
    try {
      if (target instanceof LibraryRef) {
        return resolveFunction(((LibraryRef)target).getLibraryName(),ctx);
      }
      if (target instanceof Expression) {
        throw new IllegalArgumentException("String_Node_Str");
      }
      throw new IllegalArgumentException(String.format("String_Node_Str",target.getClass().getName()));
    }
  finally {
      targets.push(target);
    }
  }
  return resolveFunction(null,ctx);
}
Program: 11091
Project: 11091
Buggy source:
@Override public Expression visitMemberInvocation(@NotNull cqlParser.MemberInvocationContext ctx){
  String identifier=parseString(ctx.identifier());
  if (!targets.empty()) {
    return resolveAccessor(targets.peek(),identifier);
  }
  return resolveIdentifier(identifier);
}

Fixed version (ground truth):
@Override public Expression visitMemberInvocation(@NotNull cqlParser.MemberInvocationContext ctx){
  String identifier=parseString(ctx.identifier());
  if (!targets.empty()) {
    Expression target=targets.pop();
    try {
      return resolveAccessor(target,identifier);
    }
  finally {
      targets.push(target);
    }
  }
  return resolveIdentifier(identifier);
}
Program: 11092
Project: 11092
Buggy source:
private String convertToJSON(Library library) throws JAXBException {
  JAXBContext jc=JAXBContext.newInstance(Library.class);
  Marshaller marshaller=jc.createMarshaller();
  marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT,true);
  marshaller.setProperty("String_Node_Str","String_Node_Str");
  StringWriter writer=new StringWriter();
  marshaller.marshal(new ObjectFactory().createLibrary(library),writer);
  return writer.getBuffer().toString();
}

Fixed version (ground truth):
private String convertToJSON(Library library) throws JAXBException {
  JAXBContext jc=JAXBContext.newInstance(Library.class,Annotation.class);
  Marshaller marshaller=jc.createMarshaller();
  marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT,true);
  marshaller.setProperty("String_Node_Str","String_Node_Str");
  StringWriter writer=new StringWriter();
  marshaller.marshal(new ObjectFactory().createLibrary(library),writer);
  return writer.getBuffer().toString();
}
Program: 11093
Project: 11093
Buggy source:
private String convertToJSON(Library library) throws JAXBException {
  JAXBContext jc=JAXBContext.newInstance(Library.class);
  Marshaller marshaller=jc.createMarshaller();
  marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT,true);
  marshaller.setProperty("String_Node_Str","String_Node_Str");
  StringWriter writer=new StringWriter();
  marshaller.marshal(new ObjectFactory().createLibrary(library),writer);
  return writer.getBuffer().toString();
}

Fixed version (ground truth):
private String convertToJSON(Library library) throws JAXBException {
  JAXBContext jc=JAXBContext.newInstance(Library.class,Annotation.class);
  Marshaller marshaller=jc.createMarshaller();
  marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT,true);
  marshaller.setProperty("String_Node_Str","String_Node_Str");
  StringWriter writer=new StringWriter();
  marshaller.marshal(new ObjectFactory().createLibrary(library),writer);
  return writer.getBuffer().toString();
}
Program: 11094
Project: 11094
Buggy source:
@Override public Object visitCastExpression(@NotNull cqlParser.CastExpressionContext ctx){
  As as=of.createAs().withOperand(parseExpression(ctx.expression())).withAsTypeSpecifier(parseTypeSpecifier(ctx.typeSpecifier())).withStrict(true);
  as.setResultType(as.getAsTypeSpecifier().getResultType());
  return as;
}

Fixed version (ground truth):
@Override public Object visitCastExpression(@NotNull cqlParser.CastExpressionContext ctx){
  As as=of.createAs().withOperand(parseExpression(ctx.expression())).withAsTypeSpecifier(parseTypeSpecifier(ctx.typeSpecifier())).withStrict(true);
  DataType targetType=as.getAsTypeSpecifier().getResultType();
  DataTypes.verifyCast(targetType,as.getOperand().getResultType());
  as.setResultType(targetType);
  return as;
}
Program: 11095
Project: 11095
Buggy source:
@Override public Object visitTypeExpression(@NotNull cqlParser.TypeExpressionContext ctx){
  if (ctx.getChild(1).getText().equals("String_Node_Str")) {
    Is is=of.createIs().withOperand(parseExpression(ctx.expression())).withIsTypeSpecifier(parseTypeSpecifier(ctx.typeSpecifier()));
    is.setResultType(resolveTypeName("String_Node_Str"));
    return is;
  }
  As as=of.createAs().withOperand(parseExpression(ctx.expression())).withAsTypeSpecifier(parseTypeSpecifier(ctx.typeSpecifier())).withStrict(false);
  as.setResultType(as.getAsTypeSpecifier().getResultType());
  return as;
}

Fixed version (ground truth):
@Override public Object visitTypeExpression(@NotNull cqlParser.TypeExpressionContext ctx){
  if (ctx.getChild(1).getText().equals("String_Node_Str")) {
    Is is=of.createIs().withOperand(parseExpression(ctx.expression())).withIsTypeSpecifier(parseTypeSpecifier(ctx.typeSpecifier()));
    is.setResultType(resolveTypeName("String_Node_Str"));
    return is;
  }
  As as=of.createAs().withOperand(parseExpression(ctx.expression())).withAsTypeSpecifier(parseTypeSpecifier(ctx.typeSpecifier())).withStrict(false);
  DataType targetType=as.getAsTypeSpecifier().getResultType();
  DataTypes.verifyCast(targetType,as.getOperand().getResultType());
  as.setResultType(targetType);
  return as;
}
Program: 11096
Project: 11096
Buggy source:
private void runSemanticTest(String testFileName) throws IOException {
  File translationTestFile=new File(Cql2ElmVisitorTest.class.getResource(testFileName).getFile());
  CqlTranslator translator=CqlTranslator.fromFile(translationTestFile);
  for (  CqlTranslatorException error : translator.getErrors()) {
    System.err.println(String.format("String_Node_Str",error.getLocator().getStartLine(),error.getLocator().getStartChar(),error.getMessage()));
  }
  assertThat(translator.getErrors().size(),is(0));
}

Fixed version (ground truth):
private void runSemanticTest(String testFileName,int expectedErrors) throws IOException {
  File translationTestFile=new File(Cql2ElmVisitorTest.class.getResource(testFileName).getFile());
  CqlTranslator translator=CqlTranslator.fromFile(translationTestFile);
  for (  CqlTranslatorException error : translator.getErrors()) {
    System.err.println(String.format("String_Node_Str",error.getLocator().getStartLine(),error.getLocator().getStartChar(),error.getMessage()));
  }
  assertThat(translator.getErrors().size(),is(expectedErrors));
}
Program: 11097
Project: 11097
Buggy source:
@Override public Object visitFunctionDefinition(@NotNull cqlParser.FunctionDefinitionContext ctx){
  FunctionDef fun=of.createFunctionDef().withAccessLevel(parseAccessModifier(ctx.accessModifier())).withName(parseString(ctx.identifier()));
  if (ctx.operandDefinition() != null) {
    for (    cqlParser.OperandDefinitionContext opdef : ctx.operandDefinition()) {
      TypeSpecifier typeSpecifier=parseTypeSpecifier(opdef.typeSpecifier());
      fun.getOperand().add((OperandDef)of.createOperandDef().withName(parseString(opdef.identifier())).withOperandTypeSpecifier(typeSpecifier).withResultType(typeSpecifier.getResultType()));
    }
  }
  currentFunctionDef=fun;
  try {
    fun.setExpression(parseExpression(ctx.functionBody()));
  }
  finally {
    currentFunctionDef=null;
  }
  fun.setContext(currentContext);
  fun.setResultType(fun.getExpression().getResultType());
  addToLibrary(fun);
  return fun;
}

Fixed version (ground truth):
@Override public Object visitFunctionDefinition(@NotNull cqlParser.FunctionDefinitionContext ctx){
  FunctionDef fun=of.createFunctionDef().withAccessLevel(parseAccessModifier(ctx.accessModifier())).withName(parseString(ctx.identifier()));
  if (ctx.operandDefinition() != null) {
    for (    cqlParser.OperandDefinitionContext opdef : ctx.operandDefinition()) {
      TypeSpecifier typeSpecifier=parseTypeSpecifier(opdef.typeSpecifier());
      fun.getOperand().add((OperandDef)of.createOperandDef().withName(parseString(opdef.identifier())).withOperandTypeSpecifier(typeSpecifier).withResultType(typeSpecifier.getResultType()));
    }
  }
  currentFunctionDef=fun;
  pushExpressionContext(currentContext);
  try {
    fun.setExpression(parseExpression(ctx.functionBody()));
  }
  finally {
    currentFunctionDef=null;
    popExpressionContext();
  }
  fun.setContext(currentContext);
  fun.setResultType(fun.getExpression().getResultType());
  addToLibrary(fun);
  return fun;
}
Program: 11098
Project: 11098
Buggy source:
private DataType ensureCompatibleTypes(DataType first,DataType second){
  if (first.isSuperTypeOf(second) || second.isCompatibleWith(first)) {
    return first;
  }
  if (second.isSuperTypeOf(first) || first.isCompatibleWith(second)) {
    return second;
  }
  Conversion conversion=conversionMap.findConversion(second,first,true);
  if (conversion != null) {
    return first;
  }
  conversion=conversionMap.findConversion(first,second,true);
  if (conversion != null) {
    return second;
  }
  DataTypes.verifyType(second,first);
  return first;
}

Fixed version (ground truth):
private DataType ensureCompatibleTypes(DataType first,DataType second){
  if (first.equals(DataType.any)) {
    return second;
  }
  if (second.equals(DataType.any)) {
    return first;
  }
  if (first.isSuperTypeOf(second) || second.isCompatibleWith(first)) {
    return first;
  }
  if (second.isSuperTypeOf(first) || first.isCompatibleWith(second)) {
    return second;
  }
  Conversion conversion=conversionMap.findConversion(second,first,true);
  if (conversion != null) {
    return first;
  }
  conversion=conversionMap.findConversion(first,second,true);
  if (conversion != null) {
    return second;
  }
  DataTypes.verifyType(second,first);
  return first;
}
Program: 11100
Project: 11100
Buggy source:
@Override public Retrieve visitRetrieve(@NotNull cqlParser.RetrieveContext ctx){
  String model=parseString(ctx.topic().namedTypeSpecifier().modelIdentifier());
  String topic=parseString(ctx.topic().namedTypeSpecifier().identifier());
  ClassType classType=resolveTopic(model,topic);
  NamedType namedType=classType;
  if (namedType == null) {
    throw new IllegalArgumentException(String.format("String_Node_Str",topic));
  }
  Retrieve retrieve=of.createRetrieve().withDataType(dataTypeToQName((DataType)namedType)).withTemplateId(classType != null ? classType.getIdentifier() : topic);
  if (ctx.valueset() != null) {
    if (ctx.valuesetPathIdentifier() != null) {
      retrieve.setCodeProperty(parseString(ctx.valuesetPathIdentifier()));
    }
 else     if (classType != null && classType.getPrimaryCodePath() != null) {
      retrieve.setCodeProperty(classType.getPrimaryCodePath());
    }
    List<String> identifiers=(List<String>)visit(ctx.valueset());
    retrieve.setCodes(resolveQualifiedIdentifier(identifiers));
  }
  retrieves.add(retrieve);
  retrieve.setResultType(new ListType((DataType)namedType));
  return retrieve;
}

Fixed version (ground truth):
@Override public Retrieve visitRetrieve(@NotNull cqlParser.RetrieveContext ctx){
  String model=parseString(ctx.topic().namedTypeSpecifier().modelIdentifier());
  String topic=parseString(ctx.topic().namedTypeSpecifier().identifier());
  ClassType classType=resolveTopic(model,topic);
  NamedType namedType=classType;
  if (namedType == null) {
    throw new IllegalArgumentException(String.format("String_Node_Str",topic));
  }
  Retrieve retrieve=of.createRetrieve().withDataType(dataTypeToQName((DataType)namedType)).withTemplateId(classType.getIdentifier());
  if (ctx.valueset() != null) {
    if (ctx.valuesetPathIdentifier() != null) {
      retrieve.setCodeProperty(parseString(ctx.valuesetPathIdentifier()));
    }
 else     if (classType.getPrimaryCodePath() != null) {
      retrieve.setCodeProperty(classType.getPrimaryCodePath());
    }
    List<String> identifiers=(List<String>)visit(ctx.valueset());
    retrieve.setCodes(resolveQualifiedIdentifier(identifiers));
  }
  retrieves.add(retrieve);
  retrieve.setResultType(new ListType((DataType)namedType));
  return retrieve;
}
Program: 11101
Project: 11101
Buggy source:
public List<OperatorResolution> resolve(CallContext callContext,ConversionMap conversionMap){
  if (callContext == null) {
    throw new IllegalArgumentException("String_Node_Str");
  }
  List<OperatorResolution> results=signatures.resolve(callContext,conversionMap);
  if (results == null) {
    Operator result=instantiate(callContext.getSignature(),conversionMap);
    if (result != null) {
      signatures.add(new SignatureNode(result));
      results=signatures.resolve(callContext,conversionMap);
    }
  }
  return results;
}

Fixed version (ground truth):
public List<OperatorResolution> resolve(CallContext callContext,ConversionMap conversionMap){
  if (callContext == null) {
    throw new IllegalArgumentException("String_Node_Str");
  }
  List<OperatorResolution> results=signatures.resolve(callContext,conversionMap);
  if (results == null || allResultsUseConversion(results)) {
    Operator result=instantiate(callContext.getSignature(),conversionMap);
    if (result != null && !signatures.contains(result)) {
      signatures.add(new SignatureNode(result));
    }
    results=signatures.resolve(callContext,conversionMap);
  }
  return results;
}
Program: 11103
Project: 11103
Buggy source:
@Override public Retrieve visitRetrieve(@NotNull cqlParser.RetrieveContext ctx){
  String model=parseString(ctx.topic().namedTypeSpecifier().modelIdentifier());
  String topic=parseString(ctx.topic().namedTypeSpecifier().identifier());
  ClassType classType=resolveTopic(model,topic);
  NamedType namedType=classType;
  if (namedType == null) {
    namedType=(NamedType)resolveTypeName(model,topic);
    if (namedType == null) {
      throw new IllegalArgumentException(String.format("String_Node_Str",topic));
    }
  }
  Retrieve retrieve=of.createRetrieve().withDataType(dataTypeToQName((DataType)namedType)).withTemplateId(classType != null ? classType.getIdentifier() : topic);
  if (ctx.valueset() != null) {
    if (ctx.valuesetPathIdentifier() != null) {
      retrieve.setCodeProperty(parseString(ctx.valuesetPathIdentifier()));
    }
 else     if (classType != null && classType.getPrimaryCodePath() != null) {
      retrieve.setCodeProperty(classType.getPrimaryCodePath());
    }
    List<String> identifiers=(List<String>)visit(ctx.valueset());
    retrieve.setCodes(resolveQualifiedIdentifier(identifiers));
  }
  retrieves.add(retrieve);
  retrieve.setResultType(new ListType((DataType)namedType));
  return retrieve;
}

Fixed version (ground truth):
@Override public Retrieve visitRetrieve(@NotNull cqlParser.RetrieveContext ctx){
  String model=parseString(ctx.topic().namedTypeSpecifier().modelIdentifier());
  String topic=parseString(ctx.topic().namedTypeSpecifier().identifier());
  ClassType classType=resolveTopic(model,topic);
  NamedType namedType=classType;
  if (namedType == null) {
    throw new IllegalArgumentException(String.format("String_Node_Str",topic));
  }
  Retrieve retrieve=of.createRetrieve().withDataType(dataTypeToQName((DataType)namedType)).withTemplateId(classType != null ? classType.getIdentifier() : topic);
  if (ctx.valueset() != null) {
    if (ctx.valuesetPathIdentifier() != null) {
      retrieve.setCodeProperty(parseString(ctx.valuesetPathIdentifier()));
    }
 else     if (classType != null && classType.getPrimaryCodePath() != null) {
      retrieve.setCodeProperty(classType.getPrimaryCodePath());
    }
    List<String> identifiers=(List<String>)visit(ctx.valueset());
    retrieve.setCodes(resolveQualifiedIdentifier(identifiers));
  }
  retrieves.add(retrieve);
  retrieve.setResultType(new ListType((DataType)namedType));
  return retrieve;
}
Program: 11105
Project: 11105
Buggy source:
private DataType resolveTypeName(String modelName,String typeName){
  DataType result=null;
  if (modelName == null || modelName.equals("String_Node_Str")) {
    for (    Model model : models.values()) {
      DataType modelResult=model.resolveTypeName(typeName);
      if (modelResult != null) {
        if (result != null) {
          throw new IllegalArgumentException(String.format("String_Node_Str",typeName,((NamedType)result).getName(),((NamedType)modelResult).getName()));
        }
        result=modelResult;
      }
    }
  }
 else {
    result=getModel(modelName).resolveTypeName(typeName);
  }
  return result;
}

Fixed version (ground truth):
private DataType resolveTypeName(String modelName,String typeName){
  DataType result=resolveTopic(modelName,typeName);
  if (result == null) {
    if (modelName == null || modelName.equals("String_Node_Str")) {
      for (      Model model : models.values()) {
        DataType modelResult=model.resolveTypeName(typeName);
        if (modelResult != null) {
          if (result != null) {
            throw new IllegalArgumentException(String.format("String_Node_Str",typeName,((NamedType)result).getName(),((NamedType)modelResult).getName()));
          }
          result=modelResult;
        }
      }
    }
 else {
      result=getModel(modelName).resolveTypeName(typeName);
    }
  }
  return result;
}
Program: 11107
Project: 11107
Buggy source:
@Override public Object visitReturnClause(@NotNull cqlParser.ReturnClauseContext ctx){
  ReturnClause returnClause=of.createReturnClause();
  if (ctx.getChild(1) instanceof TerminalNode) {
switch (ctx.getChild(1).getText()) {
case "String_Node_Str":
      returnClause.setDistinct(false);
    break;
case "String_Node_Str":
  returnClause.setDistinct(true);
break;
default :
break;
}
}
returnClause.setExpression(parseExpression(ctx.expression()));
returnClause.setResultType(returnClause.getExpression().getResultType());
return returnClause;
}

Fixed version (ground truth):
@Override public Object visitReturnClause(@NotNull cqlParser.ReturnClauseContext ctx){
  ReturnClause returnClause=of.createReturnClause();
  if (ctx.getChild(1) instanceof TerminalNode) {
switch (ctx.getChild(1).getText()) {
case "String_Node_Str":
      returnClause.setDistinct(false);
    break;
case "String_Node_Str":
  returnClause.setDistinct(true);
break;
default :
break;
}
}
returnClause.setExpression(parseExpression(ctx.expression()));
returnClause.setResultType(queries.peek().isSingular() ? returnClause.getExpression().getResultType() : new ListType(returnClause.getExpression().getResultType()));
return returnClause;
}
Program: 11108
Project: 11108
Buggy source:
public void addQuerySource(AliasedQuerySource source){
  sources.put(source.getAlias(),source);
}

Fixed version (ground truth):
public void addQuerySource(AliasedQuerySource source){
  sources.put(source.getAlias(),source);
  if (source.getResultType() instanceof ListType) {
    isSingularValue=false;
  }
}
Program: 11109
Project: 11109
Buggy source:
@Override public Object visitTupleTypeSpecifier(@NotNull cqlParser.TupleTypeSpecifierContext ctx){
  TupleType resultType=new TupleType();
  TupleTypeSpecifier typeSpecifier=of.createTupleTypeSpecifier();
  for (  cqlParser.TupleElementDefinitionContext definitionContext : ctx.tupleElementDefinition()) {
    TupleElementDefinition element=(TupleElementDefinition)visit(definitionContext);
    resultType.addElement(new TupleTypeElement(element.getName(),element.getResultType()));
    typeSpecifier.getElement().add(element);
  }
  typeSpecifier.setResultType(resultType);
  return typeSpecifier;
}

Fixed version (ground truth):
@Override public Object visitTupleTypeSpecifier(@NotNull cqlParser.TupleTypeSpecifierContext ctx){
  TupleType resultType=new TupleType();
  TupleTypeSpecifier typeSpecifier=of.createTupleTypeSpecifier();
  for (  cqlParser.TupleElementDefinitionContext definitionContext : ctx.tupleElementDefinition()) {
    TupleElementDefinition element=(TupleElementDefinition)visit(definitionContext);
    resultType.addElement(new TupleTypeElement(element.getName(),element.getType().getResultType()));
    typeSpecifier.getElement().add(element);
  }
  typeSpecifier.setResultType(resultType);
  return typeSpecifier;
}
Program: 11110
Project: 11110
Buggy source:
public void addOperator(Operator operator){
  if (operator instanceof GenericOperator) {
    addGenericOperator((GenericOperator)operator);
  }
 else {
    if (operators.containsKey(operator.getSignature())) {
      throw new IllegalArgumentException(String.format("String_Node_Str",name,operator.getSignature().toString()));
    }
    operators.put(operator.getSignature(),operator);
  }
}

Fixed version (ground truth):
public void addOperator(Operator operator){
  if (operator instanceof GenericOperator) {
    addGenericOperator((GenericOperator)operator);
  }
 else {
    signatures.add(new SignatureNode(operator));
  }
}
Program: 11111
Project: 11111
Buggy source:
public Operator resolve(Signature signature){
  if (signature == null) {
    throw new IllegalArgumentException("String_Node_Str");
  }
  Operator result=null;
  for (  Operator o : operators.values()) {
    if (o.getSignature().isSuperTypeOf(signature)) {
      if (result != null) {
        throw new IllegalArgumentException(String.format("String_Node_Str",this.name,signature,result.getSignature(),o.getSignature()));
      }
      result=o;
    }
  }
  if (result == null) {
    result=instantiate(signature);
    if (result != null) {
      operators.put(result.getSignature(),result);
    }
  }
  return result;
}

Fixed version (ground truth):
public Operator resolve(Signature signature){
  if (signature == null) {
    throw new IllegalArgumentException("String_Node_Str");
  }
  Operator result=signatures.resolve(signature);
  if (result == null) {
    result=instantiate(signature);
    if (result != null) {
      signatures.add(new SignatureNode(result));
    }
  }
  return result;
}
Program: 11113
Project: 11113
Buggy source:
private QName dataTypeToQName(DataType type){
  if (type instanceof NamedType) {
    NamedType namedType=(NamedType)type;
    return new QName(getModelHelper(namedType.getNamespace()).getModelInfo().getUrl(),namedType.getSimpleName());
  }
  throw new IllegalArgumentException("String_Node_Str");
}

Fixed version (ground truth):
private QName dataTypeToQName(DataType type){
  if (type instanceof NamedType) {
    NamedType namedType=(NamedType)type;
    org.hl7.elm_modelinfo.r1.ModelInfo modelInfo=getModelHelper(namedType.getNamespace()).getModelInfo();
    return new QName(modelInfo.getUrl(),namedType.getSimpleName());
  }
  throw new IllegalArgumentException("String_Node_Str");
}