From 71a74b9e9be3bfbad11231b043819e7cea969f53 Mon Sep 17 00:00:00 2001 From: Andrei Gurau Date: Fri, 27 Oct 2023 10:39:16 -0400 Subject: [PATCH] [Java][Dataflow Runner] Add precondition to make sure userAgent name and version are not empty (#29157) --- .../apache/beam/runners/dataflow/DataflowRunner.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/runners/google-cloud-dataflow-java/src/main/java/org/apache/beam/runners/dataflow/DataflowRunner.java b/runners/google-cloud-dataflow-java/src/main/java/org/apache/beam/runners/dataflow/DataflowRunner.java index 80b4e4cfd8b5..6449053194fe 100644 --- a/runners/google-cloud-dataflow-java/src/main/java/org/apache/beam/runners/dataflow/DataflowRunner.java +++ b/runners/google-cloud-dataflow-java/src/main/java/org/apache/beam/runners/dataflow/DataflowRunner.java @@ -403,11 +403,14 @@ && isServiceEndpoint(dataflowOptions.getDataflowEndpoint())) { } DataflowRunnerInfo dataflowRunnerInfo = DataflowRunnerInfo.getDataflowRunnerInfo(); + String userAgentName = dataflowRunnerInfo.getName(); + Preconditions.checkArgument( + !userAgentName.equals(""), "Dataflow runner's `name` property cannot be empty."); + String userAgentVersion = dataflowRunnerInfo.getVersion(); + Preconditions.checkArgument( + !userAgentVersion.equals(""), "Dataflow runner's `version` property cannot be empty."); String userAgent = - String.format( - "%s/%s%s", - dataflowRunnerInfo.getName(), dataflowRunnerInfo.getVersion(), agentJavaVer) - .replace(" ", "_"); + String.format("%s/%s%s", userAgentName, userAgentVersion, agentJavaVer).replace(" ", "_"); dataflowOptions.setUserAgent(userAgent); return new DataflowRunner(dataflowOptions);