Fix error-prone PreconditionsCheckNotNullPrimitive

This commit is contained in:
Andrew Gaul 2015-03-29 15:56:09 -07:00
parent 32ab9596be
commit 866ac3fabb
31 changed files with 48 additions and 70 deletions

View File

@ -47,9 +47,9 @@ public class ContainerCDNMetadata implements Comparable<ContainerCDNMetadata> {
public ContainerCDNMetadata(String name, boolean cdnEnabled, boolean logRetention, long ttl,
@Nullable URI cdnUri, @Nullable URI cdnSslUri, @Nullable URI cdnStreamingUri, @Nullable URI cdnIosUri) {
this.name = checkNotNull(name, "name");
this.cdnEnabled = checkNotNull(cdnEnabled);
this.logRetention = checkNotNull(logRetention);
this.ttl = checkNotNull(ttl);
this.cdnEnabled = cdnEnabled;
this.logRetention = logRetention;
this.ttl = ttl;
this.cdnUri = cdnUri;
this.cdnSslUri = cdnSslUri;
this.cdnStreamingUri = cdnStreamingUri;

View File

@ -78,7 +78,7 @@ public class Alarm {
int period, String stateReason, Optional<String> stateReasonData, Date stateUpdatedTimestamp,
State state, Statistics statistic, double threshold, Optional<Unit> unit) {
this.alarmName = checkNotNull(alarmName, "alarmName");
this.areActionsEnabled = checkNotNull(areActionsEnabled, "actionsEnabled for %s", alarmName);
this.areActionsEnabled = areActionsEnabled;
this.alarmActions = checkNotNull(alarmActions, "alarmActions for %s", alarmName);
this.alarmARN = checkNotNull(alarmARN, "alarmArn for %s", alarmName);
this.alarmConfigurationUpdatedTimestamp = checkNotNull(alarmConfigurationUpdatedTimestamp,
@ -87,12 +87,12 @@ public class Alarm {
this.comparisonOperator = checkNotNull(comparisonOperator, "comparisonOperator for %s", alarmName);
checkArgument(comparisonOperator != ComparisonOperator.UNRECOGNIZED, "comparisonOperator unrecognized");
this.dimensions = checkNotNull(dimensions, "dimensions for %s", alarmName);
this.evaluationPeriods = checkNotNull(evaluationPeriods, "evaluationPeriods for %s", alarmName);
this.evaluationPeriods = evaluationPeriods;
this.insufficientDataActions = checkNotNull(insufficientDataActions, "insufficientDataActions for %s", alarmName);
this.metricName = checkNotNull(metricName, "metricName for %s", alarmName);
this.namespace = checkNotNull(namespace, "namespace for %s", alarmName);
this.okActions = checkNotNull(okActions, "okActions for %s", alarmName);
this.period = checkNotNull(period, "period for %s", alarmName);
this.period = period;
this.stateReason = checkNotNull(stateReason, "stateReason for %s", alarmName);
this.stateReasonData = checkNotNull(stateReasonData, "stateReasonData for %s", alarmName);
this.stateUpdatedTimestamp = checkNotNull(stateUpdatedTimestamp, "stateUpdatedTimestamp for %s", alarmName);
@ -100,7 +100,7 @@ public class Alarm {
checkArgument(state != State.UNRECOGNIZED, "state unrecognized");
this.statistic = checkNotNull(statistic, "statistic for %s", alarmName);
checkArgument(statistic != Statistics.UNRECOGNIZED, "statistic unrecognized");
this.threshold = checkNotNull(threshold, "threshold for %s", alarmName);
this.threshold = threshold;
this.unit = checkNotNull(unit, "unit for %s", alarmName);
if (unit.isPresent()) {
checkArgument(unit.get() != Unit.UNRECOGNIZED, "unit unrecognized");

View File

@ -85,7 +85,7 @@ public class ListAlarmHistoryOptions extends BaseHttpRequestOptions {
* @return this {@code ListAlarmHistoryOptions} object
*/
public ListAlarmHistoryOptions maxRecords(int maxRecords) {
formParameters.put("MaxRecords", checkNotNull(maxRecords, "maxRecords").toString());
formParameters.put("MaxRecords", String.valueOf(maxRecords));
return this;
}

View File

@ -103,7 +103,7 @@ public class ListAlarmsForMetric extends BaseHttpRequestOptions {
* @return this {@code ListAlarmsForMetric} object
*/
public ListAlarmsForMetric period(int period) {
formParameters.put("Period", checkNotNull(period, "period").toString());
formParameters.put("Period", String.valueOf(period));
return this;
}

View File

@ -97,7 +97,7 @@ public class ListAlarmsOptions extends BaseHttpRequestOptions {
* @return this {@code ListAlarmsOptions} object
*/
public ListAlarmsOptions maxRecords(int maxRecords) {
formParameters.put("MaxRecords", checkNotNull(maxRecords, "maxRecords").toString());
formParameters.put("MaxRecords", String.valueOf(maxRecords));
return this;
}

View File

@ -49,7 +49,7 @@ public class SaveAlarmOptions extends BaseHttpRequestOptions {
* @return this {@code SaveAlarmOptions} object
*/
public SaveAlarmOptions actionsEnabled(boolean actionsEnabled) {
formParameters.put("ActionsEnabled", checkNotNull(actionsEnabled, "actionsEnabled").toString());
formParameters.put("ActionsEnabled", String.valueOf(actionsEnabled));
return this;
}
@ -158,7 +158,7 @@ public class SaveAlarmOptions extends BaseHttpRequestOptions {
* @return this {@code SaveAlarmOptions} object
*/
public SaveAlarmOptions evaluationPeriods(int evaluationPeriods) {
formParameters.put("EvaluationPeriods", checkNotNull(evaluationPeriods, "evaluationPeriods").toString());
formParameters.put("EvaluationPeriods", String.valueOf(evaluationPeriods));
return this;
}
@ -254,7 +254,7 @@ public class SaveAlarmOptions extends BaseHttpRequestOptions {
* @return this {@code SaveAlarmOptions} object
*/
public SaveAlarmOptions period(int period) {
formParameters.put("Period", checkNotNull(period, "period").toString());
formParameters.put("Period", String.valueOf(period));
return this;
}
@ -280,7 +280,7 @@ public class SaveAlarmOptions extends BaseHttpRequestOptions {
* @return this {@code SaveAlarmOptions} object
*/
public SaveAlarmOptions threshold(double threshold) {
formParameters.put("Threshold", checkNotNull(threshold).toString());
formParameters.put("Threshold", String.valueOf(threshold));
return this;
}

View File

@ -114,7 +114,7 @@ public class BundleTask implements Comparable<BundleTask> {
this.bundleId = checkNotNull(bundleId, "bundleId");
this.error = error;
this.instanceId = checkNotNull(instanceId, "instanceId");
this.progress = checkNotNull(progress, "progress");
this.progress = progress;
this.startTime = checkNotNull(startTime, "startTime");
this.state = checkNotNull(state, "state");
this.bucket = checkNotNull(bucket, "bucket");

View File

@ -172,8 +172,6 @@ public class SecurityGroupPredicates {
* @return predicate that matches startPort
*/
public static Predicate<SecurityGroupRule> ruleStartPort(final int startPort) {
checkNotNull(startPort, "startPort must be defined");
return new Predicate<SecurityGroupRule>() {
@Override
public boolean apply(SecurityGroupRule ext) {
@ -194,8 +192,6 @@ public class SecurityGroupPredicates {
* @return predicate that matches endPort
*/
public static Predicate<SecurityGroupRule> ruleEndPort(final int endPort) {
checkNotNull(endPort, "endPort must be defined");
return new Predicate<SecurityGroupRule>() {
@Override
public boolean apply(SecurityGroupRule ext) {

View File

@ -40,7 +40,7 @@ public class Segment {
private Segment(String path, String etag, long sizeBytes) {
this.path = checkNotNull(path, "path");
this.etag = checkNotNull(etag, "etag of %s", path);
this.sizeBytes = checkNotNull(sizeBytes, "sizeBytes of %s", path);
this.sizeBytes = sizeBytes;
}
/**

View File

@ -29,7 +29,7 @@ public final class Protocol {
@ConstructorProperties({ "name", "port" })
protected Protocol(String name, int port) {
this.name = checkNotNull(name, "name");
this.port = checkNotNull(port, "port");
this.port = port;
}
public String getName() {

View File

@ -35,7 +35,7 @@ public final class HostedZone {
this.id = checkNotNull(id, "id");
this.name = checkNotNull(name, "name");
this.callerReference = checkNotNull(callerReference, "callerReference for %s", name);
this.resourceRecordSetCount = checkNotNull(resourceRecordSetCount, "resourceRecordSetCount for %s", name);
this.resourceRecordSetCount = resourceRecordSetCount;
this.comment = checkNotNull(comment, "comment for %s", comment);
}

View File

@ -70,9 +70,6 @@ public class ResourceRecordSetApiLiveTest extends BaseRoute53ApiLiveTest {
if (rrs instanceof RecordSubset) {
checkNotNull(RecordSubset.class.cast(rrs).getId(), "Id: ResourceRecordSubset %s", rrs);
}
if (rrs instanceof Weighted) {
checkNotNull(Weighted.class.cast(rrs).getWeight(), "Weight: ResourceRecordSubset %s", rrs);
}
if (rrs instanceof Latency) {
checkNotNull(Latency.class.cast(rrs).getRegion(), "Region: ResourceRecordSubset %s", rrs);
}

View File

@ -91,7 +91,7 @@ public class BatchError {
private BatchError(String id, boolean senderFault, String code, String message) {
this.id = checkNotNull(id, "id");
this.senderFault = checkNotNull(senderFault, "senderFault of %s", id);
this.senderFault = senderFault;
this.code = checkNotNull(code, "code of %s", id);
this.message = checkNotNull(message, "message of %s", id);
}

View File

@ -76,7 +76,7 @@ public final class UserAndSessionCredentials {
private UserAndSessionCredentials(User user, SessionCredentials credentials, int packedPolicySize) {
this.user = checkNotNull(user, "user");
this.credentials = checkNotNull(credentials, "credentials for %s", user);
this.packedPolicySize = checkNotNull(packedPolicySize, "packedPolicySize for %s", user);
this.packedPolicySize = packedPolicySize;
}
/**

View File

@ -48,7 +48,7 @@ public class BaseListOptions extends BaseHttpRequestOptions {
*/
public BaseListOptions startAt(long offset) {
checkState(offset >= 0, "offset must be >= 0");
queryParameters.put("offset", Long.toString(checkNotNull(offset, "offset")));
queryParameters.put("offset", String.valueOf(offset));
return this;
}

View File

@ -746,11 +746,11 @@
</compilerArgs>
</configuration>
<dependencies>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-compiler-javac-errorprone</artifactId>
<version>2.5</version>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-compiler-javac-errorprone</artifactId>
<version>2.5</version>
</dependency>
</dependencies>
</plugin>
<plugin>

View File

@ -40,7 +40,7 @@ public final class CreatePrimaryZone {
private CreatePrimaryZone(String fqdn, String contact, SerialStyle serialStyle, int defaultTTL) {
this.fqdn = checkNotNull(fqdn, "fqdn");
this.contact = checkNotNull(contact, "contact for %s", fqdn);
this.defaultTTL = checkNotNull(defaultTTL, "defaultTTL for %s", fqdn);
this.defaultTTL = defaultTTL;
this.serialStyle = checkNotNull(serialStyle, "serialStyle for %s", serialStyle);
}

View File

@ -35,8 +35,8 @@ public class GeoService {
private GeoService(String name, boolean active, int ttl, List<Node> nodes, List<GeoRegionGroup> groups) {
this.name = checkNotNull(name, "name");
this.active = checkNotNull(active, "active");
this.ttl = checkNotNull(ttl, "ttl");
this.active = active;
this.ttl = ttl;
this.nodes = checkNotNull(nodes, "nodes of %s", name);
this.groups = checkNotNull(groups, "groups of %s", name);
}

View File

@ -34,7 +34,7 @@ public final class Job {
@ConstructorProperties({ "job_id", "status" })
private Job(long id, Status status) {
this.id = checkNotNull(id, "id");
this.id = id;
this.status = checkNotNull(status, "status for %s", id);
}

View File

@ -33,7 +33,7 @@ public class RecordId extends Node {
@ConstructorProperties({"zone", "fqdn", "record_type", "record_id" })
RecordId(String zone, String fqdn, String type, long id) {
super(zone, fqdn);
this.id = checkNotNull(id, "id");
this.id = id;
this.type = checkNotNull(type, "type of %s", id);
}

View File

@ -90,7 +90,7 @@ public final class Zone {
private Zone(String fqdn, Type type, int serial, SerialStyle serialStyle) {
this.fqdn = checkNotNull(fqdn, "fqdn");
this.type = checkNotNull(type, "type for %s", fqdn);
this.serial = checkNotNull(serial, "serial for %s", fqdn);
this.serial = serial;
this.serialStyle = checkNotNull(serialStyle, "serialStyle for %s", serialStyle);
}

View File

@ -70,11 +70,12 @@ public class SOAData extends ForwardingMap<String, Object> {
this.delegate = ImmutableMap.<String, Object> builder()
.put("mname", checkNotNull(mname, "mname"))
.put("rname", checkNotNull(rname, "rname of %s", mname))
.put("serial", checkNotNull(serial, "serial of %s", mname))
.put("refresh", checkNotNull(refresh, "refresh of %s", mname))
.put("retry", checkNotNull(retry, "retry of %s", mname))
.put("expire", checkNotNull(expire, "expire of %s", mname))
.put("minimum", checkNotNull(minimum, "minimum of %s", mname)).build();
.put("serial", serial)
.put("refresh", refresh)
.put("retry", retry)
.put("expire", expire)
.put("minimum", minimum)
.build();
}
/**

View File

@ -48,11 +48,11 @@ public class SRVData extends ForwardingMap<String, Object> {
@ConstructorProperties({ "priority", "weight", "port", "target" })
private SRVData(int priority, int weight, int port, String target) {
checkArgument(checkNotNull(priority, "priority of %s", target).intValue() <= 0xFFFF, "priority must be 0-65535");
checkArgument(priority <= 0xFFFF, "priority must be 0-65535");
this.priority = priority;
checkArgument(checkNotNull(weight, "weight of %s", target).intValue() <= 0xFFFF, "weight must be 0-65535");
checkArgument(weight <= 0xFFFF, "weight must be 0-65535");
this.weight = weight;
checkArgument(checkNotNull(port, "port of %s", target).intValue() <= 0xFFFF, "port must be 0-65535");
checkArgument(port <= 0xFFFF, "port must be 0-65535");
this.port = port;
this.target = checkNotNull(target, "target");
this.delegate = ImmutableMap.<String, Object> builder()

View File

@ -64,7 +64,6 @@ public class RecordApiLiveTest extends BaseDynECTApiLiveTest {
checkRecordId(record);
assertTrue(!record.getRData().isEmpty(), "RData entries should be present for cannot be zero for Record: "
+ record);
checkNotNull(record.getTTL(), "TTL cannot be null for RecordId: %s", record);
}
@Test
@ -127,7 +126,6 @@ public class RecordApiLiveTest extends BaseDynECTApiLiveTest {
private Record<MXData> checkMXRecord(Record<MXData> record) {
MXData rdata = record.getRData();
checkNotNull(rdata.getPreference(), "rdata.preference cannot be null for MXRecord: %s", record);
checkNotNull(rdata.getExchange(), "rdata.exchange cannot be null for MXRecord: %s", record);
return record;
}
@ -149,11 +147,6 @@ public class RecordApiLiveTest extends BaseDynECTApiLiveTest {
SOAData rdata = record.getRData();
checkNotNull(rdata.getMname(), "rdata.mname cannot be null for SOARecord: %s", record);
checkNotNull(rdata.getRname(), "rdata.rname cannot be null for SOARecord: %s", record);
checkNotNull(rdata.getSerial(), "rdata.serial cannot be null for SOARecord: %s", record);
checkNotNull(rdata.getRefresh(), "rdata.refresh cannot be null for SOARecord: %s", record);
checkNotNull(rdata.getRetry(), "rdata.retry cannot be null for SOARecord: %s", record);
checkNotNull(rdata.getExpire(), "rdata.expire cannot be null for SOARecord: %s", record);
checkNotNull(rdata.getMinimum(), "rdata.minimum cannot be null for SOARecord: %s", record);
return record;
}
@ -165,17 +158,12 @@ public class RecordApiLiveTest extends BaseDynECTApiLiveTest {
private Record<SRVData> checkSRVRecord(Record<SRVData> record) {
SRVData rdata = record.getRData();
checkNotNull(rdata.getPriority(), "rdata.priority cannot be null for SRVRecord: %s", record);
checkNotNull(rdata.getWeight(), "rdata.weight cannot be null for SRVRecord: %s", record);
checkNotNull(rdata.getPort(), "rdata.port cannot be null for SRVRecord: %s", record);
checkNotNull(rdata.getTarget(), "rdata.target cannot be null for SRVRecord: %s", record);
return record;
}
private Record<SSHFPData> checkSSHFPRecord(Record<SSHFPData> record) {
SSHFPData rdata = record.getRData();
checkNotNull(rdata.getAlgorithm(), "rdata.algorithm cannot be null for SSHFPRecord: %s", record);
checkNotNull(rdata.getType(), "rdata.type cannot be null for SSHFPRecord: %s", record);
checkNotNull(rdata.getFingerprint(), "rdata.fingerprint cannot be null for SSHFPRecord: %s", record);
return record;
}

View File

@ -36,7 +36,6 @@ public class ZoneApiLiveTest extends BaseDynECTApiLiveTest {
private void checkZone(Zone zone) {
checkNotNull(zone.getFQDN(), "FQDN cannot be null for a Zone: %s", zone);
checkNotNull(zone.getSerial(), "Serial cannot be null for a Zone: %s", zone);
}
@Test

View File

@ -216,7 +216,7 @@ public class IpDetails {
@Nullable String netmask, @Nullable String broadcast, @Nullable String gateway,
List<String> nameServers, @Nullable String serverId, Cost cost, GleSYSBoolean reserved) {
this.datacenter = checkNotNull(datacenter, "datacenter");
this.version = checkNotNull(version, "version");
this.version = version;
this.ptr = checkNotNull(ptr, "ptr");
this.platform = checkNotNull(platform, "platform");
this.address = address;

View File

@ -82,8 +82,8 @@ public class VirtualGuestToJson implements Binder {
TemplateObject.Builder templateObjectBuilder = TemplateObject.builder();
String hostname = checkNotNull(virtualGuest.getHostname(), "hostname");
String domain = checkNotNull(virtualGuest.getDomain(), "domain");
int startCpus = checkNotNull(virtualGuest.getStartCpus(), "startCpus");
int maxMemory = checkNotNull(virtualGuest.getMaxMemory(), "maxMemory");
int startCpus = virtualGuest.getStartCpus();
int maxMemory = virtualGuest.getMaxMemory();
boolean hourlyBillingFlag = virtualGuest.isHourlyBillingFlag();
boolean localDisk = virtualGuest.isLocalDiskFlag();

View File

@ -165,19 +165,16 @@ public class SoftLayerTemplateOptions extends TemplateOptions implements Cloneab
}
public SoftLayerTemplateOptions hourlyBillingFlag(boolean hourlyBillingFlag) {
checkNotNull(hourlyBillingFlag, "hourlyBillingFlag was null");
this.hourlyBillingFlag = Optional.of(hourlyBillingFlag);
return this;
}
public SoftLayerTemplateOptions dedicatedAccountHostOnlyFlag(boolean dedicatedAccountHostOnlyFlag) {
checkNotNull(dedicatedAccountHostOnlyFlag, "dedicatedAccountHostOnlyFlag was null");
this.dedicatedAccountHostOnlyFlag = Optional.of(dedicatedAccountHostOnlyFlag);
return this;
}
public SoftLayerTemplateOptions privateNetworkOnlyFlag(boolean privateNetworkOnlyFlag) {
checkNotNull(privateNetworkOnlyFlag, "privateNetworkOnlyFlag was null");
this.privateNetworkOnlyFlag = Optional.of(privateNetworkOnlyFlag);
return this;
}

View File

@ -113,8 +113,8 @@ public class SoftLayerComputeServiceAdapter implements
@Named(PROPERTY_SOFTLAYER_VIRTUALGUEST_LOGIN_DETAILS_DELAY) long guestLoginDelay,
@Named(PROPERTY_SOFTLAYER_VIRTUALGUEST_ACTIVE_TRANSACTIONS_DELAY) long activeTransactionsDelay) {
this.api = checkNotNull(api, "api");
this.guestLoginDelay = checkNotNull(guestLoginDelay, "guestLoginDelay");
this.activeTransactionsDelay = checkNotNull(activeTransactionsDelay, "activeTransactionsDelay");
this.guestLoginDelay = guestLoginDelay;
this.activeTransactionsDelay = activeTransactionsDelay;
this.createObjectOptionsSupplier = checkNotNull(createObjectOptionsSupplier, "createObjectOptionsSupplier");
checkArgument(guestLoginDelay > 500, "guestOrderDelay must be in milliseconds and greater than 500");
this.loginDetailsTester = retry(virtualGuestHasLoginDetailsPresent, guestLoginDelay);

View File

@ -193,7 +193,7 @@ public class Address {
@Nullable String address, @Nullable String city, @Nullable String contactName,
int isActive, int locationId, @Nullable String postalCode) {
this.id = id;
this.accountId = checkNotNull(accountId, "accountId");
this.accountId = accountId;
this.address = address;
this.city = city;
this.contactName = contactName;

View File

@ -39,7 +39,7 @@ public final class ZoneProperties {
this.typeCode = typeCode;
this.type = checkNotNull(type, "type for %s", name);
this.modified = checkNotNull(modified, "modified for %s", name);
this.resourceRecordCount = checkNotNull(resourceRecordCount, "resourceRecordCount for %s", name);
this.resourceRecordCount = resourceRecordCount;
}
/**