Program: 65470
Project: 65470
Buggy source:
/** 
 * @param dataExpr
 * @param odiResult
 * @param scope
 * @param logger
 * @return
 * @throws BirtException
 */
public static Object evaluateExpression(IBaseExpression dataExpr,IResultIterator odiResult,Scriptable scope,ScriptContext cx) throws BirtException {
  Object exprValue=null;
  if (dataExpr == null)   throw new DataException(ResourceConstants.BAD_DATA_EXPRESSION);
  Object handle=dataExpr.getHandle();
  if (handle instanceof ICompiledScript) {
    return cx.newContext(scope).evaluate((ICompiledScript)handle);
  }
 else   if (handle instanceof CompiledExpression) {
    CompiledExpression expr=(CompiledExpression)handle;
    Object value=evaluateCompiledExpression(expr,odiResult,scope,cx);
    try {
      if (value instanceof BirtException)       throw (BirtException)value;
      exprValue=DataTypeUtil.convert(value,dataExpr.getDataType());
    }
 catch (    BirtException e) {
      throw DataException.wrap(e);
    }
  }
 else   if (handle instanceof ConditionalExpression) {
    ConditionalExpression ce=(ConditionalExpression)handle;
    Object resultExpr=evaluateExpression(ce.getExpression(),odiResult,scope,cx);
    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]=evaluateExpression(ce.getOperand1(),odiResult,scope,cx);
      }
 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]=evaluateExpression((IBaseExpression)exprs[i],odiResult,scope,cx);
        }
        op1Value=flatternMultipleValues(result);
      }
    }
    if (ce.getOperand2() != null) {
      if (ce.getOperand2() instanceof IScriptExpression) {
        op2Value=new Object[1];
        op2Value[0]=evaluateExpression(ce.getOperand2(),odiResult,scope,cx);
      }
    }
    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;
}

Fixed version (ground truth):
/** 
 * @param dataExpr
 * @param odiResult
 * @param scope
 * @param logger
 * @return
 * @throws BirtException
 */
public static Object evaluateExpression(IBaseExpression dataExpr,IResultIterator odiResult,Scriptable scope,ScriptContext cx) throws BirtException {
  Object exprValue=null;
  if (dataExpr == null)   throw new DataException(ResourceConstants.BAD_DATA_EXPRESSION);
  Object handle=dataExpr.getHandle();
  if (handle instanceof ICompiledScript) {
    return cx.newContext(scope).evaluate((ICompiledScript)handle);
  }
 else   if (handle instanceof CompiledExpression) {
    CompiledExpression expr=(CompiledExpression)handle;
    Object value=evaluateCompiledExpression(expr,odiResult,scope,cx);
    try {
      if (value instanceof BirtException)       throw (BirtException)value;
      exprValue=DataTypeUtil.convert(value,dataExpr.getDataType());
    }
 catch (    BirtException e) {
      throw DataException.wrap(e);
    }
  }
 else   if (handle instanceof ConditionalExpression) {
    ConditionalExpression ce=(ConditionalExpression)handle;
    Object resultExpr=evaluateExpression(ce.getExpression(),odiResult,scope,cx);
    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]=evaluateExpression(ce.getOperand1(),odiResult,scope,cx);
      }
 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]=evaluateExpression((IBaseExpression)exprs[i],odiResult,scope,cx);
        }
        op1Value=flatternMultipleValues(result);
      }
    }
    if (ce.getOperand2() != null) {
      if (ce.getOperand2() instanceof IScriptExpression) {
        op2Value=new Object[1];
        op2Value[0]=evaluateExpression(ce.getOperand2(),odiResult,scope,cx);
      }
    }
    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   if (BaseExpression.constantId.equals(dataExpr.getScriptId())) {
    Object value=((IScriptExpression)dataExpr).getHandle();
    if (value == null) {
      value=((IScriptExpression)dataExpr).getText();
      ((IScriptExpression)dataExpr).setHandle(value);
    }
    exprValue=DataTypeUtil.convert(value,dataExpr.getDataType());
    return exprValue;
  }
 else {
    DataException e=new DataException(ResourceConstants.INVALID_EXPR_HANDLE);
    throw e;
  }
  return exprValue;
}