improve service methods through validation library

Hi there,

I am looking into making the radiology modules service methods cleaner, easier to read.

What I mean by that is that every public method always needs to check their parameters for validity (not null, not empty, …). Sometimes this makes them really bloated.

So I am checking out libraries that do the checking for me.

I found http://qualitycheck.sourceforge.net/ which is nice since its a little (~50kB) library.

And it turns

setObject(final Object object) {
	if (object != null) {
		throw new IllegalArgumentException("Argument 'object' must not be null.");
	}
	this.object = object;
}

becomes

setObject(final Object object) {
	this.object = Check.notNull(object);
}

and throws its own specific expressive exceptions. In above case IllegalNullArgumentException

The only issue I am having with the library is that the latest release was on Aug 1, 2013.

Another one is apache.commons-lang

https://commons.apache.org/proper/commons-lang/javadocs/api-3.1/org/apache/commons/lang3/Validate.html

to which I already have a dependency coming from the openmrs core, so thats a big + and of course this one is still actively developed.

It does not have own specific exceptions instead it uses NullPointerException, IllegalArgumentException, …

Based on active development and having the dependency already I would rather use Apache’s Validate.

I am interested in your thoughts on using such a library: do you think it is good practice? what are your reservations?

Why not just use Spring validation classes instead of adding new libraries?

http://docs.spring.io/spring/docs/current/spring-framework-reference/html/validation.html

Do Java 8’s annotations like @NonNull solve this problem?

-Darius (by phone)