From 6ff03ae5310fae455a279f1ad9b786ab3f82207b Mon Sep 17 00:00:00 2001 From: Jochen Schalanda Date: Wed, 11 Dec 2024 14:35:44 +0100 Subject: [PATCH] Fix ClassCastException in HttpOperations#initShortId() (#3542) Calling `HttpOperations#initShortId()` could cause a `ClassCastException` if the underlying connection was replaced between checking its type and casting it to `AtomicLong`, for example if `ChannelOperations#terminate()` was called on another thread. See also: https://github.com/reactor/reactor-netty/blob/667f8c9cbf5a227a15f6d0a2f3aab7c4777613da/reactor-netty-core/src/main/java/reactor/netty/channel/ChannelOperations.java#L515 Fixes #3541 Co-authored-by: Violeta Georgieva --- .../src/main/java/reactor/netty/http/HttpOperations.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/reactor-netty-http/src/main/java/reactor/netty/http/HttpOperations.java b/reactor-netty-http/src/main/java/reactor/netty/http/HttpOperations.java index 96f4c3d848..64126acc95 100644 --- a/reactor-netty-http/src/main/java/reactor/netty/http/HttpOperations.java +++ b/reactor-netty-http/src/main/java/reactor/netty/http/HttpOperations.java @@ -377,8 +377,9 @@ protected final boolean markSentHeaderAndBody(Object... objectsToRelease) { @Override protected final String initShortId() { - if (connection() instanceof AtomicLong) { - return channel().id().asShortText() + '-' + ((AtomicLong) connection()).incrementAndGet(); + Connection connection = connection(); + if (connection instanceof AtomicLong) { + return connection.channel().id().asShortText() + '-' + ((AtomicLong) connection).incrementAndGet(); } return super.initShortId(); }