Validation Framework
My new employer has no current standards for data validation.
Basically, there's no parameter checking and no usage of assert
statements anywhere.
I've decided we need a library to facilitate a transition to a more
sane environment. I have two questions:
1. Is there any prewritten library, or is this something I should
be writing myself? Right now I'm just looking at basic methods,
like assertNotNull(), assertNoNullElements, things like that.
2. Right now in my bare-bones library, I have numerous methods for
dealing with arrays. For instance, I need nine instances of
publicstaticvoid assertValidIndex(finalint index,final Object[] array,
final String arrayName)
throws AssertionError{
ValidationUtilities.assertNotNull(array, arrayName);
assert (ValidationUtilities.isValidIndex(index, array.length)) :
"The index " + index +" is out of bounds for array " + arrayName;
}
, one for Object[] and eight for the primitive types. Is there any way
around this? I suspect not, but I'm game to be surprised. :)
I could force an end user to push index and array.length, but then
they would need to do null checking also.
[1656 byte] By [
es5f2000a] at [2007-11-26 19:27:23]

# 2
> My new employer has no current standards for data
> validation.
> Basically, there's no parameter checking and no usage
> of assert
> statements anywhere.
You seem to take that as a negative. Does your employer require and enforce formal code reviews? That lack is far more serious. Does you employer formally estimate and track projects? Again that lack is far more serious. If you employer is doing both of those then in terms of software developement the lack of parameter checking might not even be measurable in terms of significance (but with sufficient process control levels one can actually measure that to determine it.)
Normally "data validation" would not be equivalent to "parameter checking".
In a database layer I might choose to validate the data (making sure that values that must be non-null for the database are indeed non-null) and I might also choose to validate parameters. Those are completely different needs and are driven by different sources.
There is certainly no need to do parameter validation on every single method. Certainly one should probably start by excluding private methods from that requirement.
On the other hand data validation, IMHO, should always be done at every major interface layer.
> Right now in my bare-bones library,
> I have numerous methods for dealing with arrays
I am rather certain that aspect oriented compilers deal with all of that.