commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Cyrille Artho <>
Subject [math] Design issue: many constructors build incomplete instances
Date Wed, 16 Apr 2014 06:53:51 GMT
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 

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.
Cyrille Artho -
Some cause happiness wherever they go; others, whenever they go.
		-- Oscar Wilde

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message