From 24d9b963114beaa1164aa4ab49efaad82f7f82ab Mon Sep 17 00:00:00 2001 From: Kannan J Date: Wed, 25 Mar 2026 12:28:07 +0000 Subject: [PATCH 1/5] Remove extraneous changes beyond avoiding the false positive warnings, since super.shutdown() is never expected to throw. Also remove redundant unit test. Rework of PR #12705. --- .../internal/ManagedChannelOrphanWrapper.java | 3 +-- .../ManagedChannelOrphanWrapperTest.java | 25 ------------------- 2 files changed, 1 insertion(+), 27 deletions(-) diff --git a/core/src/main/java/io/grpc/internal/ManagedChannelOrphanWrapper.java b/core/src/main/java/io/grpc/internal/ManagedChannelOrphanWrapper.java index c7f722a9499..f75fbfd5193 100644 --- a/core/src/main/java/io/grpc/internal/ManagedChannelOrphanWrapper.java +++ b/core/src/main/java/io/grpc/internal/ManagedChannelOrphanWrapper.java @@ -73,13 +73,12 @@ public ManagedChannel shutdown() { @Override public ManagedChannel shutdownNow() { - ManagedChannel result = super.shutdownNow(); phantom.clearSafely(); // This dummy check prevents the JIT from collecting 'this' too early if (this.getClass() == null) { throw new AssertionError(); } - return result; + return super.shutdownNow(); } @VisibleForTesting diff --git a/core/src/test/java/io/grpc/internal/ManagedChannelOrphanWrapperTest.java b/core/src/test/java/io/grpc/internal/ManagedChannelOrphanWrapperTest.java index cdd36fb8273..45fb3881722 100644 --- a/core/src/test/java/io/grpc/internal/ManagedChannelOrphanWrapperTest.java +++ b/core/src/test/java/io/grpc/internal/ManagedChannelOrphanWrapperTest.java @@ -140,31 +140,6 @@ public boolean isLoggable(LogRecord record) { } } - @Test - public void orphanedChannel_triggerWarningAndCoverage() { - ManagedChannel mc = new TestManagedChannel(); - final ReferenceQueue refqueue = new ReferenceQueue<>(); - ConcurrentMap refs = - new ConcurrentHashMap<>(); - - // Create the wrapper but NEVER call shutdown - @SuppressWarnings("UnusedVariable") - ManagedChannelOrphanWrapper wrapper = new ManagedChannelOrphanWrapper(mc, refqueue, refs); - wrapper = null; // Make it eligible for GC - - // Trigger GC and clean the queue to hit the !wasShutdown branch - final AtomicInteger numOrphans = new AtomicInteger(); - GcFinalization.awaitDone(new FinalizationPredicate() { - @Override - public boolean isDone() { - numOrphans.getAndAdd(ManagedChannelReference.cleanQueue(refqueue)); - return numOrphans.get() > 0; - } - }); - - assertEquals(1, numOrphans.get()); - } - @Test public void refCycleIsGCed() { ReferenceQueue refqueue = From e5d24f531835f6fec343e2c765e214ee4fd13e30 Mon Sep 17 00:00:00 2001 From: Kannan J Date: Wed, 25 Mar 2026 12:28:07 +0000 Subject: [PATCH 2/5] Remove extraneous changes beyond avoiding the false positive warnings, since super.shutdown() is never expected to throw. Also remove redundant unit test. Rework of PR #12705. --- .../ManagedChannelOrphanWrapperTest.java | 25 ------------------- 1 file changed, 25 deletions(-) diff --git a/core/src/test/java/io/grpc/internal/ManagedChannelOrphanWrapperTest.java b/core/src/test/java/io/grpc/internal/ManagedChannelOrphanWrapperTest.java index cdd36fb8273..45fb3881722 100644 --- a/core/src/test/java/io/grpc/internal/ManagedChannelOrphanWrapperTest.java +++ b/core/src/test/java/io/grpc/internal/ManagedChannelOrphanWrapperTest.java @@ -140,31 +140,6 @@ public boolean isLoggable(LogRecord record) { } } - @Test - public void orphanedChannel_triggerWarningAndCoverage() { - ManagedChannel mc = new TestManagedChannel(); - final ReferenceQueue refqueue = new ReferenceQueue<>(); - ConcurrentMap refs = - new ConcurrentHashMap<>(); - - // Create the wrapper but NEVER call shutdown - @SuppressWarnings("UnusedVariable") - ManagedChannelOrphanWrapper wrapper = new ManagedChannelOrphanWrapper(mc, refqueue, refs); - wrapper = null; // Make it eligible for GC - - // Trigger GC and clean the queue to hit the !wasShutdown branch - final AtomicInteger numOrphans = new AtomicInteger(); - GcFinalization.awaitDone(new FinalizationPredicate() { - @Override - public boolean isDone() { - numOrphans.getAndAdd(ManagedChannelReference.cleanQueue(refqueue)); - return numOrphans.get() > 0; - } - }); - - assertEquals(1, numOrphans.get()); - } - @Test public void refCycleIsGCed() { ReferenceQueue refqueue = From cdaca1dd03383916c2af20ffbd1ee5898b912c46 Mon Sep 17 00:00:00 2001 From: Kannan J Date: Thu, 26 Mar 2026 05:33:11 +0000 Subject: [PATCH 3/5] Remove extraneous changes beyond avoiding the false positive warnings, since super.shutdown() is never expected to throw. Also remove redundant unit test. Rework of PR #12705. --- .../java/io/grpc/internal/ManagedChannelOrphanWrapper.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/io/grpc/internal/ManagedChannelOrphanWrapper.java b/core/src/main/java/io/grpc/internal/ManagedChannelOrphanWrapper.java index f75fbfd5193..c7f722a9499 100644 --- a/core/src/main/java/io/grpc/internal/ManagedChannelOrphanWrapper.java +++ b/core/src/main/java/io/grpc/internal/ManagedChannelOrphanWrapper.java @@ -73,12 +73,13 @@ public ManagedChannel shutdown() { @Override public ManagedChannel shutdownNow() { + ManagedChannel result = super.shutdownNow(); phantom.clearSafely(); // This dummy check prevents the JIT from collecting 'this' too early if (this.getClass() == null) { throw new AssertionError(); } - return super.shutdownNow(); + return result; } @VisibleForTesting From 20d9eff425aee7fc989a75d400b5d16307922bac Mon Sep 17 00:00:00 2001 From: Kannan J Date: Thu, 26 Mar 2026 05:33:11 +0000 Subject: [PATCH 4/5] Remove extraneous changes beyond avoiding the false positive warnings, since super.shutdown() is never expected to throw. Also remove redundant unit test. Rework of PR #12705. --- .../java/io/grpc/internal/ManagedChannelOrphanWrapper.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/core/src/main/java/io/grpc/internal/ManagedChannelOrphanWrapper.java b/core/src/main/java/io/grpc/internal/ManagedChannelOrphanWrapper.java index f75fbfd5193..790d5bd297f 100644 --- a/core/src/main/java/io/grpc/internal/ManagedChannelOrphanWrapper.java +++ b/core/src/main/java/io/grpc/internal/ManagedChannelOrphanWrapper.java @@ -62,13 +62,12 @@ final class ManagedChannelOrphanWrapper extends ForwardingManagedChannel { @Override public ManagedChannel shutdown() { - ManagedChannel result = super.shutdown(); phantom.clearSafely(); // This dummy check prevents the JIT from collecting 'this' too early if (this.getClass() == null) { throw new AssertionError(); } - return result; + return super.shutdown(); } @Override From ec32ad708c9fb569c36cc429be949505835efbee Mon Sep 17 00:00:00 2001 From: Kannan J Date: Thu, 26 Mar 2026 05:36:44 +0000 Subject: [PATCH 5/5] Remove extraneous changes beyond avoiding the false positive warnings, since super.shutdown() is never expected to throw. Also remove redundant unit test. Rework of PR #12705. --- .../java/io/grpc/internal/ManagedChannelOrphanWrapper.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/core/src/main/java/io/grpc/internal/ManagedChannelOrphanWrapper.java b/core/src/main/java/io/grpc/internal/ManagedChannelOrphanWrapper.java index 6569b3ba1a3..790d5bd297f 100644 --- a/core/src/main/java/io/grpc/internal/ManagedChannelOrphanWrapper.java +++ b/core/src/main/java/io/grpc/internal/ManagedChannelOrphanWrapper.java @@ -72,13 +72,12 @@ public ManagedChannel shutdown() { @Override public ManagedChannel shutdownNow() { - ManagedChannel result = super.shutdownNow(); phantom.clearSafely(); // This dummy check prevents the JIT from collecting 'this' too early if (this.getClass() == null) { throw new AssertionError(); } - return result; + return super.shutdownNow(); } @VisibleForTesting