Program: 10989
Project: 10989
Buggy source:
public Expression convertExpression(Expression expression,Conversion conversion){
  if (conversion.isCast() && (conversion.getFromType().isSuperTypeOf(conversion.getToType()) || conversion.getFromType().isCompatibleWith(conversion.getToType()))) {
    As castedOperand=(As)of.createAs().withOperand(expression).withResultType(conversion.getToType());
    castedOperand.setAsTypeSpecifier(dataTypeToTypeSpecifier(castedOperand.getResultType()));
    if (castedOperand.getResultType() instanceof NamedType) {
      castedOperand.setAsType(dataTypeToQName(castedOperand.getResultType()));
    }
    return castedOperand;
  }
 else   if (conversion.isCast() && conversion.getConversion() != null && (conversion.getFromType().isSuperTypeOf(conversion.getConversion().getFromType()) || conversion.getFromType().isCompatibleWith(conversion.getConversion().getFromType()))) {
    As castedOperand=(As)of.createAs().withOperand(expression).withResultType(conversion.getConversion().getFromType());
    castedOperand.setAsTypeSpecifier(dataTypeToTypeSpecifier(castedOperand.getResultType()));
    if (castedOperand.getResultType() instanceof NamedType) {
      castedOperand.setAsType(dataTypeToQName(castedOperand.getResultType()));
    }
    return convertExpression(castedOperand,conversion.getConversion());
  }
 else   if (conversion.isListConversion()) {
    return convertListExpression(expression,conversion);
  }
 else   if (conversion.isListDemotion()) {
    return demoteListExpression(expression,conversion);
  }
 else   if (conversion.isListPromotion()) {
    return promoteListExpression(expression,conversion);
  }
 else   if (conversion.isIntervalConversion()) {
    return convertIntervalExpression(expression,conversion);
  }
 else   if (conversion.getOperator() != null) {
    FunctionRef functionRef=(FunctionRef)of.createFunctionRef().withLibraryName(conversion.getOperator().getLibraryName()).withName(conversion.getOperator().getName()).withOperand(expression);
    Expression systemFunction=systemFunctionResolver.resolveSystemFunction(functionRef);
    if (systemFunction != null) {
      return systemFunction;
    }
    resolveCall(functionRef.getLibraryName(),functionRef.getName(),new FunctionRefInvocation(functionRef));
    return functionRef;
  }
 else {
    if (conversion.getToType().equals(resolveTypeName("String_Node_Str","String_Node_Str"))) {
      return (Expression)of.createToBoolean().withOperand(expression).withResultType(conversion.getToType());
    }
 else     if (conversion.getToType().equals(resolveTypeName("String_Node_Str","String_Node_Str"))) {
      return (Expression)of.createToInteger().withOperand(expression).withResultType(conversion.getToType());
    }
 else     if (conversion.getToType().equals(resolveTypeName("String_Node_Str","String_Node_Str"))) {
      return (Expression)of.createToDecimal().withOperand(expression).withResultType(conversion.getToType());
    }
 else     if (conversion.getToType().equals(resolveTypeName("String_Node_Str","String_Node_Str"))) {
      return (Expression)of.createToString().withOperand(expression).withResultType(conversion.getToType());
    }
 else     if (conversion.getToType().equals(resolveTypeName("String_Node_Str","String_Node_Str"))) {
      return (Expression)of.createToDateTime().withOperand(expression).withResultType(conversion.getToType());
    }
 else     if (conversion.getToType().equals(resolveTypeName("String_Node_Str","String_Node_Str"))) {
      return (Expression)of.createToTime().withOperand(expression).withResultType(conversion.getToType());
    }
 else     if (conversion.getToType().equals(resolveTypeName("String_Node_Str","String_Node_Str"))) {
      return (Expression)of.createToQuantity().withOperand(expression).withResultType(conversion.getToType());
    }
 else {
      Convert convertedOperand=(Convert)of.createConvert().withOperand(expression).withResultType(conversion.getToType());
      if (convertedOperand.getResultType() instanceof NamedType) {
        convertedOperand.setToType(dataTypeToQName(convertedOperand.getResultType()));
      }
 else {
        convertedOperand.setToTypeSpecifier(dataTypeToTypeSpecifier(convertedOperand.getResultType()));
      }
      return convertedOperand;
    }
  }
}

Fixed version (ground truth):
public Expression convertExpression(Expression expression,Conversion conversion){
  if (conversion.isCast() && (conversion.getFromType().isSuperTypeOf(conversion.getToType()) || conversion.getFromType().isCompatibleWith(conversion.getToType()))) {
    As castedOperand=buildAs(expression,conversion.getToType());
    return castedOperand;
  }
 else   if (conversion.isCast() && conversion.getConversion() != null && (conversion.getFromType().isSuperTypeOf(conversion.getConversion().getFromType()) || conversion.getFromType().isCompatibleWith(conversion.getConversion().getFromType()))) {
    As castedOperand=buildAs(expression,conversion.getConversion().getFromType());
    Expression result=convertExpression(castedOperand,conversion.getConversion());
    if (conversion.hasAlternativeConversions()) {
      Case caseResult=of.createCase();
      caseResult.setResultType(result.getResultType());
      caseResult.withCaseItem(of.createCaseItem().withWhen(buildIs(expression,conversion.getConversion().getFromType())).withThen(result));
      for (      Conversion alternative : conversion.getAlternativeConversions()) {
        caseResult.withCaseItem(of.createCaseItem().withWhen(buildIs(expression,alternative.getFromType())).withThen(convertExpression(buildAs(expression,alternative.getFromType()),alternative)));
      }
      caseResult.withElse(buildNull(result.getResultType()));
      result=caseResult;
    }
    return result;
  }
 else   if (conversion.isListConversion()) {
    return convertListExpression(expression,conversion);
  }
 else   if (conversion.isListDemotion()) {
    return demoteListExpression(expression,conversion);
  }
 else   if (conversion.isListPromotion()) {
    return promoteListExpression(expression,conversion);
  }
 else   if (conversion.isIntervalConversion()) {
    return convertIntervalExpression(expression,conversion);
  }
 else   if (conversion.getOperator() != null) {
    FunctionRef functionRef=(FunctionRef)of.createFunctionRef().withLibraryName(conversion.getOperator().getLibraryName()).withName(conversion.getOperator().getName()).withOperand(expression);
    Expression systemFunction=systemFunctionResolver.resolveSystemFunction(functionRef);
    if (systemFunction != null) {
      return systemFunction;
    }
    resolveCall(functionRef.getLibraryName(),functionRef.getName(),new FunctionRefInvocation(functionRef));
    return functionRef;
  }
 else {
    if (conversion.getToType().equals(resolveTypeName("String_Node_Str","String_Node_Str"))) {
      return (Expression)of.createToBoolean().withOperand(expression).withResultType(conversion.getToType());
    }
 else     if (conversion.getToType().equals(resolveTypeName("String_Node_Str","String_Node_Str"))) {
      return (Expression)of.createToInteger().withOperand(expression).withResultType(conversion.getToType());
    }
 else     if (conversion.getToType().equals(resolveTypeName("String_Node_Str","String_Node_Str"))) {
      return (Expression)of.createToDecimal().withOperand(expression).withResultType(conversion.getToType());
    }
 else     if (conversion.getToType().equals(resolveTypeName("String_Node_Str","String_Node_Str"))) {
      return (Expression)of.createToString().withOperand(expression).withResultType(conversion.getToType());
    }
 else     if (conversion.getToType().equals(resolveTypeName("String_Node_Str","String_Node_Str"))) {
      return (Expression)of.createToDateTime().withOperand(expression).withResultType(conversion.getToType());
    }
 else     if (conversion.getToType().equals(resolveTypeName("String_Node_Str","String_Node_Str"))) {
      return (Expression)of.createToTime().withOperand(expression).withResultType(conversion.getToType());
    }
 else     if (conversion.getToType().equals(resolveTypeName("String_Node_Str","String_Node_Str"))) {
      return (Expression)of.createToQuantity().withOperand(expression).withResultType(conversion.getToType());
    }
 else {
      Convert convertedOperand=(Convert)of.createConvert().withOperand(expression).withResultType(conversion.getToType());
      if (convertedOperand.getResultType() instanceof NamedType) {
        convertedOperand.setToType(dataTypeToQName(convertedOperand.getResultType()));
      }
 else {
        convertedOperand.setToTypeSpecifier(dataTypeToTypeSpecifier(convertedOperand.getResultType()));
      }
      return convertedOperand;
    }
  }
}