Dear all,
We have recently reported a couple of problems found in the math library that were found by automated testing (using the Randoop tool). In many cases, using a constructor without subsequent setters results in an incomplete instance. Calculations using such an instance result in a NullPointerException:

https://issues.apache.org/jira/browse/MATH-1116

Such exceptions should be advertised in the code/Javadoc, but it would be even better if they can be avoided altogether. If some data is mandatory, it could be included in the constructor (making other variants deprecated).

Of course, sometimes a lot of parameters are needed, and a constructor with too many arguments is not ideal either. In that case, a helper class XYData may hold some of the data, reducing the number of arguments.

Fortunately, it seems the cases we found usually do not require quite as many parameters. Ideally there would be no zero-argument constructors if such instances are unusable; instead, there would be constructors having all the essential arguments, to avoid subsequent NullPointerExceptions due to missing data.

Thanks for Gilles for bringing this up as way to not just clarifying errors, but avoiding them altogether.
--
Regards,
Cyrille Artho - http://artho.com/
Some cause happiness wherever they go; others, whenever they go.
                -- Oscar Wilde

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

Reply via email to