From 2636d5dda005f5a5e26127251f4cd14e757091e6 Mon Sep 17 00:00:00 2001 From: Kannan J Date: Thu, 14 Nov 2024 22:04:10 +0530 Subject: [PATCH] api: When forwarding from Listener onAddresses to Listener2 continue to use onResult (#11666) (#11688) When forwarding from Listener onAddresses to Listener2 continue to use onResult and not onResult2 because the latter requires to be called from within synchronization context and it breaks existing code that didn't need to do so when using the old Listener interface. --- api/src/main/java/io/grpc/NameResolver.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/api/src/main/java/io/grpc/NameResolver.java b/api/src/main/java/io/grpc/NameResolver.java index b9590ab5d5a..a1dea016377 100644 --- a/api/src/main/java/io/grpc/NameResolver.java +++ b/api/src/main/java/io/grpc/NameResolver.java @@ -219,13 +219,15 @@ public abstract static class Listener2 implements Listener { @Override @Deprecated @InlineMe( - replacement = "this.onResult2(ResolutionResult.newBuilder().setAddressesOrError(" + replacement = "this.onResult(ResolutionResult.newBuilder().setAddressesOrError(" + "StatusOr.fromValue(servers)).setAttributes(attributes).build())", imports = {"io.grpc.NameResolver.ResolutionResult", "io.grpc.StatusOr"}) public final void onAddresses( List servers, @ResolutionResultAttr Attributes attributes) { // TODO(jihuncho) need to promote Listener2 if we want to use ConfigOrError - onResult2( + // Calling onResult and not onResult2 because onResult2 can only be called from a + // synchronization context. + onResult( ResolutionResult.newBuilder().setAddressesOrError( StatusOr.fromValue(servers)).setAttributes(attributes).build()); }