From 29229f726218228a9ed424e35644a1305b25b545 Mon Sep 17 00:00:00 2001 From: Mike Eltsufin Date: Fri, 29 Sep 2023 15:46:24 -0400 Subject: [PATCH] fix: guard against null projectId in Firestore routing header Fixes: #2205. --- .../firestore/GcpFirestoreAutoConfiguration.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/spring-cloud-gcp-autoconfigure/src/main/java/com/google/cloud/spring/autoconfigure/firestore/GcpFirestoreAutoConfiguration.java b/spring-cloud-gcp-autoconfigure/src/main/java/com/google/cloud/spring/autoconfigure/firestore/GcpFirestoreAutoConfiguration.java index 153e112b0c..260a83adec 100644 --- a/spring-cloud-gcp-autoconfigure/src/main/java/com/google/cloud/spring/autoconfigure/firestore/GcpFirestoreAutoConfiguration.java +++ b/spring-cloud-gcp-autoconfigure/src/main/java/com/google/cloud/spring/autoconfigure/firestore/GcpFirestoreAutoConfiguration.java @@ -166,11 +166,13 @@ public FirestoreTemplate firestoreTemplate( public ClientInterceptor firestoreRoutingHeadersInterceptor() { // add routing header for custom database id Metadata routingHeader = new Metadata(); - Metadata.Key key = - Metadata.Key.of(Headers.DYNAMIC_ROUTING_HEADER_KEY, Metadata.ASCII_STRING_MARSHALLER); - routingHeader.put(key, - "project_id=" + PERCENT_ESCAPER.escape(projectId) - + "&database_id=" + PERCENT_ESCAPER.escape(databaseId)); + if (projectId != null && databaseId != null) { + Metadata.Key key = + Metadata.Key.of(Headers.DYNAMIC_ROUTING_HEADER_KEY, Metadata.ASCII_STRING_MARSHALLER); + routingHeader.put(key, + "project_id=" + PERCENT_ESCAPER.escape(projectId) + + "&database_id=" + PERCENT_ESCAPER.escape(databaseId)); + } return MetadataUtils.newAttachHeadersInterceptor(routingHeader); }