Am 2019-12-31 um 17:18 schrieb Mark James:
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);
Not, that is still wrong. null results in NullPointerException, not IAE.
You need two if statements.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]