> @@ -37,17 +38,9 @@
> public void validate(String description) {
> if (isNullOrEmpty(description))
> return;
> - if (description.length() > MAX_DESC_LENGTH)
> - throw exception("Description can't be longer than " +
> MAX_DESC_LENGTH + " characters" + " but was " + description.length());
> - if (!DESCRIPTION_ACCEPTABLE_RANGE.matchesAllOf(description))
> - throw exception("Description should have ASCII values between 32
> and 126.");
> - }
> -
> - protected static IllegalArgumentException exception(String reason) {
> - return new IllegalArgumentException(
> - String.format(
> - "Description doesn't match Glacier archive description
> rules. "
> - + "Reason: %s. For more info, please refer to
> http://docs.aws.amazon.com/amazonglacier/latest/dev/api-archive-post.html.",
> - reason));
> + checkArgument(description.length() <= MAX_DESC_LENGTH,
> + "Description can't be longer than " + MAX_DESC_LENGTH + "
> characters" + " but was " + description.length());
Java eagerly evaluates all arguments, so we build this string every time.
Instead you can call the multi-argument constructor which will only build the
formatted string when the assertion fails:
```
checkArgument(description.length() <= MAX_DESC_LENGTH,
"Description can't be longer than %d characters but was %d",
MAX_DESC_LENGTH, description.length());
```
---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-labs-aws/pull/20/files#r14000633