After writing my billionth null check in Java code, I started wondering why the ability to null check method arguments wasn't already built in to Java. For example, for some methods, I want to throw an IllegalArgumentException if some (or all) of the arguments are null. It would be great if I could mark up the code, and have the compiler generate the validation which throws an informative Exception if the validation fails.
Is there anything already in Java where you can specify some correctness parameters for method arguments (e.g. int has to be within certain range, or Object has to be not null), and have the Compiler auto-generate the code?
In Java it seems like this should be handled with annotations. (I guess in C/C++ you could define some nice macros to do this for you.) In searching the web on this issue, I saw reference to JSR 305, but this seems targeted toward use with IDE tools, and not with the Java compiler.
I'm guessing this already exists in other programming languages. So I would be interested to hear about how this may work in these languages, as well as what might exist (or be coming up) in Java.