On 9/10/12 11:47 AM, Sébastien Brisard wrote:
> Hi
> What should I do there?
> I'm trying to work on MATH-854. It turns out that FieldElement<T>.add
> throws a NAE. Should I catch it below, and rethrow it with a more
> detailed message (including the entry index)?

IMO, yes.

I would also check v itself and add to the javadoc contract that IAE
is thrown if v is null.  This is not consistently done in [math],
though, and rarely in the linear package, so I am OK just letting
the NPE propagate if v is null.   It is a little awkward that v
itself being null leads to NPE, but a component of it null leads to
MIAE.

Phil
>
> Best,
> Sébastien
>
>
>     /** {@inheritDoc} */
>     public FieldVector<T> add(FieldVector<T> v)
>             throws DimensionMismatchException {
>         try {
>             return add((ArrayFieldVector<T>) v);
>         } catch (ClassCastException cce) {
>             checkVectorDimensions(v);
>             T[] out = buildArray(data.length);
>             for (int i = 0; i < data.length; i++) {
>                 out[i] = data[i].add(v.getEntry(i));
>                 // SHOULD I CATCH NAE HERE?
>             }
>             return new ArrayFieldVector<T>(field, out, false);
>         }
>     }
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscr...@commons.apache.org
> For additional commands, e-mail: dev-h...@commons.apache.org
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@commons.apache.org
For additional commands, e-mail: dev-h...@commons.apache.org

Reply via email to