Hello, I have some concerns regarding of *Validate* class with the case of null pointer exceptions. I see that there are some misleading messages, for example:
Validate.notEmpty((Object[]) null); => throws "java.lang.NullPointerException" with the message "The validated array is empty". I don't think this message is relevant. Validate.notEmpty((Object[]) null, "MSG"); => throws "java.lang.NullPointerException" with the message "MSG". I don't think this message for this exception is relevant, either. There are cases listed below for this ill-relevant behavior. And: Validate.noNullElements((Object[]) null); => throws "java.lang.NullPointerException" with the message "The validated object is null". I believe that this is contextual relevant exception and intended behavior. Validate.noNullElements((Object[]) null); => throws "java.lang.NullPointerException" with the message "The validated object is null". => It's ok. Please make sure the consistent behaviors with these. /** * Expected: java.lang.NullPointerException: The validated object is null * Actual: java.lang.NullPointerException: The validated array is empty */ Validate.notEmpty((Object[]) null); /** * Expected: java.lang.NullPointerException: The validated object is null * Actual: java.lang.NullPointerException: MSG */ Validate.notEmpty((Object[]) null, "MSG"); /** * Expected: java.lang.NullPointerException: The validated object is null * Actual: java.lang.NullPointerException: The validated collection is empty */ Validate.notEmpty((Collection<?>) null); /** * Expected: java.lang.NullPointerException: The validated object is null * Actual: java.lang.NullPointerException: MSG */ Validate.notEmpty((Collection<?>) null, "MSG"); /** * Expected: java.lang.NullPointerException: The validated object is null * Actual: java.lang.NullPointerException: The validated map is empty */ Validate.notEmpty((Map<?, ?>) null); /** * Expected: java.lang.NullPointerException: The validated object is null * Actual: java.lang.NullPointerException: MSG */ Validate.notEmpty((Map<?, ?>) null, "MSG"); /** * Expected: java.lang.NullPointerException: The validated object is null * Actual: java.lang.NullPointerException: The validated character sequence is empty */ Validate.notEmpty((CharSequence) null); /** * Expected: java.lang.NullPointerException: The validated object is null * Actual: java.lang.NullPointerException: MSG */ Validate.notEmpty((CharSequence) null, "MSG"); /** * Expected: java.lang.NullPointerException: The validated object is null * Actual: java.lang.NullPointerException: The validated character sequence is blank */ Validate.notBlank((CharSequence) null); /** * Expected: java.lang.NullPointerException: The validated object is null * Actual: java.lang.NullPointerException: MSG */ Validate.notBlank((CharSequence) null, "MSG"); /** * Ok: java.lang.NullPointerException: The validated object is null */ Validate.noNullElements((Object[]) null); /** * Ok: java.lang.NullPointerException: The validated object is null */ Validate.noNullElements((Object[]) null, "MSG"); Validate.validIndex(...); //=> ok will null If you agree on the expected NullPointerException, please consider my attached patch for this issue; there are duplicated code in *Validate* class, and some unit test parts for *ValidateTest* are not relevant, too. Thanks and best regards! -- Hoat Le [hoatle.net]
--------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@commons.apache.org For additional commands, e-mail: dev-h...@commons.apache.org