Enforce nullness consistency on EppResponse.set...() methods

The callsites were inconsistent between whether they were passing empty list or
null, and many of the ones that were passing null were not correctly annotated
with @Nullable. I'm now going with empty list throughout except for the final
step where the actual field that will be transformed into XML is set, where it
is coerced to null to avoid an empty element in the XML output.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=139340837
This commit is contained in:
mcilwain 2016-11-16 09:25:44 -08:00 committed by Ben McIlwain
parent 4d2e0941f3
commit 5368489987
10 changed files with 27 additions and 24 deletions

View file

@ -394,7 +394,7 @@ public class DomainAllocateFlow implements TransactionalFlow {
FeeCreateCommandExtension feeCreate =
eppInput.getSingleExtension(FeeCreateCommandExtension.class);
return (feeCreate == null)
? null
? ImmutableList.of()
: ImmutableList.of(createFeeCreateResponse(feeCreate, commandOperations));
}

View file

@ -177,7 +177,7 @@ public final class DomainCheckFlow implements Flow {
FeeCheckCommandExtension<?, ?> feeCheck =
eppInput.getSingleExtension(FeeCheckCommandExtension.class);
if (feeCheck == null) {
return null; // No fee checks were requested.
return ImmutableList.of(); // No fee checks were requested.
}
ImmutableList.Builder<FeeCheckResponseExtensionItem> responseItems =
new ImmutableList.Builder<>();

View file

@ -439,7 +439,7 @@ public class DomainCreateFlow implements TransactionalFlow {
private ImmutableList<FeeTransformResponseExtension> createResponseExtensions(
FeeCreateCommandExtension feeCreate, EppCommandOperations commandOperations) {
return (feeCreate == null)
? null
? ImmutableList.of()
: ImmutableList.of(createFeeCreateResponse(feeCreate, commandOperations));
}

View file

@ -221,7 +221,7 @@ public final class DomainDeleteFlow implements TransactionalFlow {
DomainResource existingDomain, DateTime now) {
FeeTransformResponseExtension.Builder feeResponseBuilder = getDeleteResponseBuilder();
if (feeResponseBuilder == null) {
return null;
return ImmutableList.of();
}
ImmutableList.Builder<Credit> creditsBuilder = new ImmutableList.Builder<>();
for (GracePeriod gracePeriod : existingDomain.getGracePeriods()) {
@ -234,7 +234,7 @@ public final class DomainDeleteFlow implements TransactionalFlow {
}
ImmutableList<Credit> credits = creditsBuilder.build();
if (credits.isEmpty()) {
return null;
return ImmutableList.of();
}
return ImmutableList.of(feeResponseBuilder.setCredits(credits).build());
}

View file

@ -19,7 +19,6 @@ import static google.registry.flows.ResourceFlowUtils.loadAndVerifyExistence;
import static google.registry.flows.ResourceFlowUtils.verifyOptionalAuthInfo;
import static google.registry.flows.domain.DomainFlowUtils.addSecDnsExtensionIfPresent;
import static google.registry.flows.domain.DomainFlowUtils.handleFeeRequest;
import static google.registry.util.CollectionUtils.forceEmptyToNull;
import com.google.common.base.Optional;
import com.google.common.collect.ImmutableList;
@ -149,6 +148,6 @@ public final class DomainInfoFlow implements Flow {
extensions.add(FlagsInfoResponseExtension.create(ImmutableList.copyOf(flags)));
}
}
return forceEmptyToNull(extensions.build());
return extensions.build();
}
}

View file

@ -216,8 +216,9 @@ public final class DomainRenewFlow implements TransactionalFlow {
private ImmutableList<FeeTransformResponseExtension> createResponseExtensions(
Money renewCost, FeeRenewCommandExtension feeRenew) {
return (feeRenew == null) ? null : ImmutableList.of(feeRenew
.createResponseBuilder()
return (feeRenew == null)
? ImmutableList.of()
: ImmutableList.of(feeRenew.createResponseBuilder()
.setCurrency(renewCost.getCurrencyUnit())
.setFees(ImmutableList.of(Fee.create(renewCost.getAmount(), FeeType.RENEW)))
.build());

View file

@ -260,8 +260,9 @@ public final class DomainRestoreRequestFlow implements TransactionalFlow {
private static ImmutableList<FeeTransformResponseExtension> createResponseExtensions(
Money restoreCost, Money renewCost, FeeUpdateCommandExtension feeUpdate) {
return (feeUpdate == null) ? null : ImmutableList.of(
feeUpdate.createResponseBuilder()
return (feeUpdate == null)
? ImmutableList.of()
: ImmutableList.of(feeUpdate.createResponseBuilder()
.setCurrency(restoreCost.getCurrencyUnit())
.setFees(ImmutableList.of(
Fee.create(restoreCost.getAmount(), FeeType.RESTORE),

View file

@ -408,7 +408,7 @@ public final class DomainTransferRequestFlow implements TransactionalFlow {
private ImmutableList<FeeTransformResponseExtension> createResponseExtensions(Money renewCost,
FeeTransferCommandExtension feeTransfer) {
return feeTransfer == null
? null
? ImmutableList.of()
: ImmutableList.of(feeTransfer.createResponseBuilder()
.setCurrency(renewCost.getCurrencyUnit())
.setFees(ImmutableList.of(Fee.create(renewCost.getAmount(), FeeType.RENEW)))

View file

@ -18,7 +18,6 @@ import static google.registry.flows.FlowUtils.validateClientIsLoggedIn;
import static google.registry.flows.poll.PollFlowUtils.getPollMessagesQuery;
import static google.registry.model.eppoutput.Result.Code.SUCCESS_WITH_ACK_MESSAGE;
import static google.registry.model.eppoutput.Result.Code.SUCCESS_WITH_NO_MESSAGES;
import static google.registry.util.CollectionUtils.forceEmptyToNull;
import com.googlecode.objectify.Key;
import google.registry.flows.EppException;
@ -76,8 +75,8 @@ public class PollRequestFlow implements Flow {
.setQueueLength(getPollMessagesQuery(clientId, now).count())
.setMessageId(PollMessage.EXTERNAL_KEY_CONVERTER.convert(Key.create(pollMessage)))
.build())
.setMultipleResData(forceEmptyToNull(pollMessage.getResponseData()))
.setExtensions(forceEmptyToNull(pollMessage.getResponseExtensions()))
.setMultipleResData(pollMessage.getResponseData())
.setExtensions(pollMessage.getResponseExtensions())
.build();
}

View file

@ -14,6 +14,9 @@
package google.registry.model.eppoutput;
import static google.registry.util.CollectionUtils.forceEmptyToNull;
import static google.registry.util.CollectionUtils.nullToEmptyImmutableCopy;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.ImmutableList;
import google.registry.model.Buildable;
@ -150,11 +153,11 @@ public class EppResponse extends ImmutableObject implements ResponseOrGreeting {
ImmutableList<? extends ResponseExtension> extensions;
public ImmutableList<? extends ResponseData> getResponseData() {
return resData;
return nullToEmptyImmutableCopy(resData);
}
public ImmutableList<? extends ResponseExtension> getExtensions() {
return extensions;
return nullToEmptyImmutableCopy(extensions);
}
@Nullable
@ -216,8 +219,8 @@ public class EppResponse extends ImmutableObject implements ResponseOrGreeting {
return setMultipleResData(ImmutableList.of(onlyResData));
}
public Builder setMultipleResData(@Nullable ImmutableList<? extends ResponseData> resData) {
getInstance().resData = resData;
public Builder setMultipleResData(ImmutableList<? extends ResponseData> resData) {
getInstance().resData = forceEmptyToNull(resData);
return this;
}
@ -225,8 +228,8 @@ public class EppResponse extends ImmutableObject implements ResponseOrGreeting {
return setExtensions(ImmutableList.of(onlyExtension));
}
public Builder setExtensions(@Nullable ImmutableList<? extends ResponseExtension> extensions) {
getInstance().extensions = extensions;
public Builder setExtensions(ImmutableList<? extends ResponseExtension> extensions) {
getInstance().extensions = forceEmptyToNull(extensions);
return this;
}
}