View Full Version : RE: [Mondrian] Problems with functions throwingexceptionslike CastFunDef

Pappyn Bart
01-04-2007, 04:22 AM
Hi Julian,

final Object o = evaluate(evaluator); does evaluate to null sometimes
when not in cache. But not a NullPointerException is thrown,
but a RuntimeException. This due to the way CastFunDef is programmed.
After RuntimeException, evaluation of the query stops.

I patched CastFunDef.evaluateDouble, CastFunDef.evaluateInteger and
CastFunDef.evaluateBoolean to return the
special null values. Since then everything works fine.

example CastFunDef :

public String evaluateString(Evaluator evaluator) {
final Object o = evaluate(evaluator);
if (o == null) {
return null; // --> This is original code, o
sometimes evaluates to null when not in cache yet.
return String.valueOf(o);

public double evaluateDouble(Evaluator evaluator) {
final Object o = evaluate(evaluator);

// --> This is the piece of code I added to
evaluateDouble, since then everything works fine, otherwise in the past
// --> cannotConvert(o) was called.
if (o == null) {
return FunUtil.DoubleNull;
if (o instanceof String) {
return Double.valueOf((String) o);
if (o instanceof Number) {
return ((Number) o).doubleValue();
throw cannotConvert(o);

if you have something like this : cast(expr as NUMERIC) * cast(expr as
NUMERIC) * cast(expr as NUMERIC)

then code in * will work with my changes :

final double v0 =
final double v1 =
// Multiply and divide return null if EITHER arg
is null.
if (v0 == DoubleNull || v1 == DoubleNull) {
return DoubleNull;
} else {
return v0 * v1;

I need cast in the example above, because expr * expr * expr -> does not
work if numeric * is needed.

If my changes are ok by you, I will check them in.

Please also keep in mind I posted another thread in the mailing list
about Multi-user access and maxEvalDepth problems.
Maybe it is related to that problem, since the CastFunDef problem
usually occurs with multi-user access. After debugging
I found a number of problems concerning multi-user access and aggregate
cache flushing. I will post a mail on my findings shortly.


-----Original Message-----
From: mondrian-bounces (AT) pentaho (DOT) org [mailto:mondrian-bounces (AT) pentaho (DOT) org]
On Behalf Of julianhyde (AT) speakeasy (DOT) net
Sent: donderdag 4 januari 2007 9:58
To: mondrian (AT) pentaho (DOT) org
Subject: Re: [Mondrian] Problems with functions throwing exceptionslike

When values are not in the cache, the value returned by expressions
should be a special value, not null. So, I'm surprised that
NullPointerException is being thrown.

Can you try making CastFunDef return null if its input is null? Maybe
that will workaround the problem and allow you to make progress.


Mondrian mailing list
Mondrian (AT) pentaho (DOT) org

This email has been scanned by the Email Security System.

Mondrian mailing list
Mondrian (AT) pentaho (DOT) org