My notBlank code was actually correct. But I hadn't made clear that this code
wasn't replacing the whole notBlank method, but only its inner part, not
changing the quick initial test, which also tests for nulls:
private static void notBlank( String str, String message )
{
int c = str != null && str.length() > 0 ? str.charAt( 0 ) : 0;
if ( ( c < '0' || c > '9' ) && ( c < 'a' || c > 'z' ) )
{
for (int i = 0; i < str.length(); i++) {
if (!Character.isWhitespace(str.charAt(i))) {
return;
}
}
throw new IllegalArgumentException(message);
}
}
On 01/01/2020 03:18, Mark James wrote:
> On 01/01/2020 01:13, Michael Osipov wrote:
>> 2. In ArtifactUtils.notBlank, replacing
>>> Validate.notBlank( str, message );
>>>
>>> with
>>>
>>> for (int i=0; i < str.length(); i++) if
>>> (!Character.isWhitespace(str.charAt(i))) return;
>>> throw new IllegalArgumentException(message);
>>>
>>> or, using Java 8 code,
>>>
>>> if (str.chars().allMatch(Character::isWhitespace)) throw new
>>> IllegalArgumentException(message);
>> These are not equivalient. Validate#notBlank throws NPE on null input, those
>> alternatives don't do. I'd has to be interface specification equal.
>>
>> M
> Thanks Michael for picking that up.
>
> So should be
>
> if (str != null) for (int i=0; i < str.length(); i++)
> if (!Character.isWhitespace(str.charAt(i))) return;
> throw new IllegalArgumentException(message);
>
> or, using Java 8 code,
>
> if (str == null || str.chars().allMatch(Character::isWhitespace))
> throw new IllegalArgumentException(message);
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]