Avoid eager evaluation of Preconditions messages

Found via error-prone.
This commit is contained in:
Andrew Gaul 2016-04-24 23:27:01 -07:00
parent e5f65a4791
commit 66cda12b50
11 changed files with 16 additions and 17 deletions

View File

@ -125,7 +125,7 @@ public class BlockDeviceMapping implements Comparable<BlockDeviceMapping> {
if (sizeInGib != null) {
checkArgument(sizeInGib >= VOLUME_SIZE_MIN_VALUE && sizeInGib <= VOLUME_SIZE_MAX_VALUE,
String.format("Size in Gib must be between %s and %s GB", VOLUME_SIZE_MIN_VALUE, VOLUME_SIZE_MAX_VALUE));
"Size in Gib must be between %s and %s GB", VOLUME_SIZE_MIN_VALUE, VOLUME_SIZE_MAX_VALUE);
}
this.deviceName = deviceName;
this.virtualName = virtualName;

View File

@ -186,7 +186,7 @@ public class CreateVolumeResponseHandler extends ParseSax.HandlerForGeneratedReq
}
}
checkNotNull(regionToZones, String.format("zone %s not in %s", zone, regionToZones));
checkNotNull(regionToZones, "zone %s not in %s", zone, regionToZones);
} else {
region = defaultRegion.get();
}

View File

@ -67,7 +67,7 @@ public class OAuthTestUtils {
if (System.getProperties().containsKey(testKey)) {
val = System.getProperty(testKey);
}
checkNotNull(val, String.format("the property %s must be set (pem private key file path or private key as a string)", testKey));
checkNotNull(val, "the property %s must be set (pem private key file path or private key as a string)", testKey);
if (val.startsWith("-----BEGIN")) {
return val;
@ -86,7 +86,7 @@ public class OAuthTestUtils {
checkNotNull(properties);
checkNotNull(key);
String value = properties.getProperty(key);
return checkNotNull(value, String.format("mandatory property %s or test.%s was not present", key, key));
return checkNotNull(value, "mandatory property %s or test.%s was not present", key, key);
}
}

View File

@ -67,8 +67,7 @@ public final class TestProperties {
val = System.getProperty(testKey);
}
checkNotNull(val,
String.format("the property %s must be set (pem private key file path or private key as a string)",
testKey));
"the property %s must be set (pem private key file path or private key as a string)", testKey);
if (val.startsWith("-----BEGIN")) {
return val;

View File

@ -242,7 +242,7 @@ public class HttpRequest extends HttpMessage {
super(headers, payload);
this.method = checkNotNull(method, "method");
this.endpoint = checkNotNull(endpoint, "endpoint");
checkArgument(endpoint.getHost() != null, String.format("endpoint.getHost() is null for %s", endpoint));
checkArgument(endpoint.getHost() != null, "endpoint.getHost() is null for %s", endpoint);
this.filters = ImmutableList.<HttpRequestFilter> copyOf(checkNotNull(filters, "filters"));
}

View File

@ -113,7 +113,7 @@ public class ParseSax<T> implements Function<HttpResponse, T>, InvocationContext
private void validateXml(String from) {
checkNotNull(from, "xml string");
checkArgument(from.indexOf('<') >= 0, String.format("not an xml document [%s] ", from));
checkArgument(from.indexOf('<') >= 0, "not an xml document [%s] ", from);
}
public T parse(InputStream from) {

View File

@ -511,7 +511,7 @@ public class RestAnnotationProcessor implements Function<Invocation, HttpRequest
try {
URI returnVal = parser.apply(invocation.getArgs().get(position));
checkArgument(returnVal != null,
format("endpoint for [%s] not configured for %s", position, invocation.getInvokable()));
"endpoint for [%s] not configured for %s", position, invocation.getInvokable());
return returnVal;
} catch (NullPointerException e) {
throw new IllegalArgumentException(format("argument at index %d on invocation.getInvoked() %s was null",

View File

@ -154,8 +154,8 @@ public class JschSshClient implements SshClient {
}
private void checkConnected() {
checkState(sessionConnection.getSession() != null && sessionConnection.getSession().isConnected(), String.format(
"(%s) Session not connected!", toString()));
checkState(sessionConnection.getSession() != null && sessionConnection.getSession().isConnected(),
"(%s) Session not connected!", this);
}
public interface Connection<T> {

View File

@ -172,8 +172,8 @@ public class SshjSshClient implements SshClient {
}
private void checkConnected() {
checkState(sshClientConnection.ssh != null && sshClientConnection.ssh.isConnected(), String
.format("(%s) ssh not connected!", toString()));
checkState(sshClientConnection.ssh != null && sshClientConnection.ssh.isConnected(),
"(%s) ssh not connected!", this);
}
public interface Connection<T> {

View File

@ -127,8 +127,8 @@ public class AWSEC2ComputeService extends EC2ComputeService {
try {
client.getPlacementGroupApi().get().deletePlacementGroupInRegion(region, placementGroup);
checkState(placementGroupDeleted.apply(new PlacementGroup(region, placementGroup, "cluster",
State.PENDING)), String.format("placementGroup region(%s) name(%s) failed to delete", region,
placementGroup));
State.PENDING)), "placementGroup region(%s) name(%s) failed to delete", region,
placementGroup);
placementGroupMap.invalidate(new RegionAndName(region, placementGroup));
logger.debug("<< deleted placementGroup(%s)", placementGroup);
} catch (IllegalStateException e) {

View File

@ -63,8 +63,8 @@ public class CreatePlacementGroupIfNeeded extends CacheLoader<RegionAndName, Str
try {
ec2Api.getPlacementGroupApi().get().createPlacementGroupInRegion(region, name);
logger.debug("<< created placementGroup(%s)", name);
checkState(placementGroupAvailable.apply(new PlacementGroup(region, name, "cluster", State.PENDING)), String
.format("placementGroup region(%s) name(%s) failed to become available", region, name));
checkState(placementGroupAvailable.apply(new PlacementGroup(region, name, "cluster", State.PENDING)),
"placementGroup region(%s) name(%s) failed to become available", region, name);
} catch (AWSResponseException e) {
if (e.getError().getCode().equals("InvalidPlacementGroup.Duplicate")) {
logger.debug("<< reused placementGroup(%s)", name);