Program: 72044
Project: 72044
Buggy source:
/** 
 * TODO: need refactoring
 * @param dataExpr
 * @return
 * @throws BirtException
 */
public static Object evaluateValue(IBaseExpression dataExpr,int index,IResultObject roObject,Scriptable scope) throws BirtException {
  Object exprValue=null;
  Object handle=dataExpr == null ? null : dataExpr.getHandle();
  if (handle instanceof CompiledExpression) {
    CompiledExpression expr=(CompiledExpression)handle;
    Object value=evaluateCompiledExpression(expr,index,roObject,scope);
    try {
      exprValue=DataTypeUtil.convert(value,dataExpr.getDataType());
    }
 catch (    BirtException e) {
      throw new DataException(ResourceConstants.INCONVERTIBLE_DATATYPE,new Object[]{value,value.getClass(),DataType.getClass(dataExpr.getDataType())});
    }
  }
 else   if (dataExpr instanceof ConditionalExpression) {
    ConditionalExpression ce=(ConditionalExpression)dataExpr;
    Object resultExpr=evaluateValue(ce.getExpression(),index,roObject,scope);
    Object[] op1Value=new Object[0], op2Value=new Object[0];
    boolean isCombined=false;
    if (ce.getOperand1() != null) {
      if (ce.getOperand1() instanceof IScriptExpression) {
        op1Value=new Object[1];
        op1Value[0]=evaluateValue(ce.getOperand1(),index,roObject,scope);
      }
 else       if (ce.getOperand1() instanceof IExpressionCollection) {
        isCombined=true;
        Object[] exprs=((IExpressionCollection)ce.getOperand1()).getExpressions().toArray();
        int length=exprs.length;
        Object[] result=new Object[length];
        for (int i=0; i < length; i++) {
          result[i]=evaluateValue((IBaseExpression)exprs[i],index,roObject,scope);
        }
        op1Value=flatternMultipleValues(result);
      }
    }
    if (ce.getOperand2() != null) {
      if (ce.getOperand2() instanceof IScriptExpression) {
        op2Value=new Object[1];
        op2Value[0]=evaluateValue(ce.getOperand2(),index,roObject,scope);
      }
 else       if (ce.getOperand2() instanceof IExpressionCollection) {
        Object[] exprs=((IExpressionCollection)ce.getOperand2()).getExpressions().toArray();
        int length=exprs.length;
        Object[] result=new Object[length];
        for (int i=0; i < length; i++) {
          result[i]=evaluateValue((IBaseExpression)exprs[i],index,roObject,scope);
        }
        op2Value=flatternMultipleValues(result);
      }
    }
    if (isCombined)     exprValue=ScriptEvalUtil.evalConditionalExpr(resultExpr,ce.getOperator(),op1Value);
 else     exprValue=ScriptEvalUtil.evalConditionalExpr(resultExpr,ce.getOperator(),op1Value.length > 0 ? op1Value[0] : null,op2Value.length > 0 ? op2Value[0] : null);
  }
 else {
    DataException e=new DataException(ResourceConstants.INVALID_EXPR_HANDLE);
    throw e;
  }
  if (exprValue instanceof DataExceptionMocker) {
    throw ((DataExceptionMocker)exprValue).getCause();
  }
  return exprValue;
}

Fixed version (ground truth):
/** 
 * TODO: need refactoring
 * @param dataExpr
 * @return
 * @throws BirtException
 */
public static Object evaluateValue(IBaseExpression dataExpr,int index,IResultObject roObject,Scriptable scope) throws BirtException {
  Object exprValue=null;
  Object handle=dataExpr == null ? null : dataExpr.getHandle();
  if (handle instanceof CompiledExpression) {
    CompiledExpression expr=(CompiledExpression)handle;
    Object value=evaluateCompiledExpression(expr,index,roObject,scope);
    try {
      exprValue=DataTypeUtil.convert(value,dataExpr.getDataType());
    }
 catch (    BirtException e) {
      throw new DataException(ResourceConstants.INCONVERTIBLE_DATATYPE,new Object[]{value,value.getClass(),DataType.getClass(dataExpr.getDataType())});
    }
  }
 else   if (dataExpr instanceof ConditionalExpression) {
    ConditionalExpression ce=(ConditionalExpression)dataExpr;
    Object resultExpr=evaluateValue(ce.getExpression(),index,roObject,scope);
    Object[] op1Value=new Object[0], op2Value=new Object[0];
    boolean isCombined=false;
    if (ce.getOperand1() != null) {
      if (ce.getOperand1() instanceof IScriptExpression) {
        op1Value=new Object[1];
        op1Value[0]=evaluateValue(ce.getOperand1(),index,roObject,scope);
      }
 else       if (ce.getOperand1() instanceof IExpressionCollection) {
        isCombined=true;
        Object[] exprs=((IExpressionCollection)ce.getOperand1()).getExpressions().toArray();
        int length=exprs.length;
        Object[] result=new Object[length];
        for (int i=0; i < length; i++) {
          result[i]=evaluateValue((IBaseExpression)exprs[i],index,roObject,scope);
        }
        op1Value=flatternMultipleValues(result);
      }
    }
    if (ce.getOperand2() != null) {
      if (ce.getOperand2() instanceof IScriptExpression) {
        op2Value=new Object[1];
        op2Value[0]=evaluateValue(ce.getOperand2(),index,roObject,scope);
      }
 else       if (ce.getOperand2() instanceof IExpressionCollection) {
        Object[] exprs=((IExpressionCollection)ce.getOperand2()).getExpressions().toArray();
        int length=exprs.length;
        Object[] result=new Object[length];
        for (int i=0; i < length; i++) {
          result[i]=evaluateValue((IBaseExpression)exprs[i],index,roObject,scope);
        }
        op2Value=flatternMultipleValues(result);
      }
    }
    if (isCombined)     exprValue=ScriptEvalUtil.evalConditionalExpr(resultExpr,ce.getOperator(),op1Value);
 else     exprValue=ScriptEvalUtil.evalConditionalExpr(resultExpr,ce.getOperator(),op1Value.length > 0 ? op1Value[0] : null,op2Value.length > 0 ? op2Value[0] : null);
  }
 else {
    DataException e=new DataException(ResourceConstants.INVALID_EXPR_HANDLE);
    throw e;
  }
  return exprValue;
}