myfaces-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Simon Lessard" <simon.lessar...@gmail.com>
Subject [TRINIDAD] Shallowed ClassCastException in SortableModel
Date Thu, 16 Oct 2008 19:50:30 GMT
Hi all,

I'm working on an ADF Faces Rich Client atm and as some may know, that
library is based on Trinidad. Anyway, while debugging for a completely
different issue, I found out the following in SortableModel class:

private int _toRowIndex(Object rowKey)
{
    if (rowKey == null)
        return -1;

    try
    {
        return ((Integer)rowKey).intValue();
    }
    catch (ClassCastException e)
    {
        _LOG.warning("INVALID_ROWKEY", new Object[]{rowKey ,
rowKey.getClass()});
        _LOG.warning(e);
        return -1;
    }
}

I think we should change that to something like the following to not shallow
an Exception that's more expensive to create than an instanceof check. Note
that for some reason I get one such exception per request currently so this
is kind of annoying ;) :

private int _toRowIndex(Object rowKey)
{
    if (rowKey == null)
    {
        return -1;
    }
    else if (rowKey instanceof Integer)
    {
        return ((Integer)rowKey).intValue();
    }
    else
    {
        _LOG.warning("INVALID_ROWKEY", new Object[]{rowKey ,
rowKey.getClass()});
        return -1;
    }
}

What do you think?


~ Simon

Mime
View raw message