You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Cyrille Artho <c....@aist.go.jp> on 2014/04/16 08:53:51 UTC

[math] Design issue: many constructors build incomplete instances

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-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org