diff --git a/java/google/registry/flows/FlowModule.java b/java/google/registry/flows/FlowModule.java index 0d1dfe6ff..aab0f04ac 100644 --- a/java/google/registry/flows/FlowModule.java +++ b/java/google/registry/flows/FlowModule.java @@ -16,6 +16,7 @@ package google.registry.flows; import static com.google.common.base.Preconditions.checkState; +import com.google.common.base.Strings; import dagger.Module; import dagger.Provides; import google.registry.flows.exceptions.OnlyToolCanPassMetadataException; @@ -27,7 +28,6 @@ import google.registry.model.eppinput.EppInput.ResourceCommandWrapper; import google.registry.model.eppinput.ResourceCommand; import google.registry.model.reporting.HistoryEntry; import java.lang.annotation.Documented; -import javax.annotation.Nullable; import javax.inject.Qualifier; /** Module to choose and instantiate an EPP flow. */ @@ -147,10 +147,11 @@ public class FlowModule { @Provides @FlowScope - @Nullable @ClientId static String provideClientId(SessionMetadata sessionMetadata) { - return sessionMetadata.getClientId(); + // Treat a missing clientId as null so we can always inject a non-null value. All we do with the + // clientId is log it (as "") or detect its absence, both of which work fine with empty. + return Strings.nullToEmpty(sessionMetadata.getClientId()); } @Provides @@ -187,7 +188,7 @@ public class FlowModule { Trid trid, @InputXml byte[] inputXmlBytes, @Superuser boolean isSuperuser, - @ClientId @Nullable String clientId, + @ClientId String clientId, EppRequestSource eppRequestSource, EppInput eppInput) { HistoryEntry.Builder historyBuilder = new HistoryEntry.Builder() diff --git a/java/google/registry/flows/FlowRunner.java b/java/google/registry/flows/FlowRunner.java index bf94c110d..0e1a95377 100644 --- a/java/google/registry/flows/FlowRunner.java +++ b/java/google/registry/flows/FlowRunner.java @@ -14,7 +14,6 @@ package google.registry.flows; -import static com.google.common.base.Strings.nullToEmpty; import static com.google.common.base.Throwables.getStackTraceAsString; import static com.google.common.io.BaseEncoding.base64; import static google.registry.model.ofy.ObjectifyService.ofy; @@ -34,7 +33,6 @@ import google.registry.model.eppoutput.EppOutput; import google.registry.monitoring.whitebox.EppMetric; import google.registry.util.Clock; import google.registry.util.FormattingLogger; -import javax.annotation.Nullable; import javax.inject.Inject; import javax.inject.Provider; import org.joda.time.DateTime; @@ -57,7 +55,7 @@ public class FlowRunner { private static final FormattingLogger logger = FormattingLogger.getLoggerForCallerClass(); - @Inject @Nullable @ClientId String clientId; + @Inject @ClientId String clientId; @Inject Clock clock; @Inject TransportCredentials credentials; @Inject EppInput eppInput; @@ -96,7 +94,7 @@ public class FlowRunner { REPORTING_LOG_SIGNATURE, JSONValue.toJSONString(ImmutableMap.of( "trid", trid.getServerTransactionId(), - "clientId", nullToEmpty(clientId), + "clientId", clientId, "xml", prettyXml, "xmlBytes", xmlBase64))); if (!isTransactional) { diff --git a/javatests/google/registry/flows/FlowRunnerTest.java b/javatests/google/registry/flows/FlowRunnerTest.java index 36aa64a17..2548f35fd 100644 --- a/javatests/google/registry/flows/FlowRunnerTest.java +++ b/javatests/google/registry/flows/FlowRunnerTest.java @@ -123,7 +123,7 @@ public class FlowRunnerTest extends ShardableTestCase { @Test public void testRun_reportingLogStatement_noClientId() throws Exception { - flowRunner.clientId = null; + flowRunner.clientId = ""; flowRunner.run(); assertThat(parseJsonMap(findLogMessageByPrefix(handler, "EPP-REPORTING-LOG-SIGNATURE: "))) .containsExactly(