Skip to content

Commit 9ee918f

Browse files
authored
Preserve exception cause in ChannelBindException (reactor#3976)
Related to spring-projects/spring-boot#47618 Signed-off-by: Violeta Georgieva <696661+violetagg@users.noreply.github.com>
1 parent 34df0fa commit 9ee918f

File tree

2 files changed

+12
-17
lines changed

2 files changed

+12
-17
lines changed

reactor-netty-core/src/main/java/reactor/netty/ChannelBindException.java

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018-2023 VMware, Inc. or its affiliates, All Rights Reserved.
2+
* Copyright (c) 2018-2025 VMware, Inc. or its affiliates, All Rights Reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -15,7 +15,6 @@
1515
*/
1616
package reactor.netty;
1717

18-
import java.io.IOException;
1918
import java.net.InetSocketAddress;
2019
import java.net.SocketAddress;
2120
import java.util.Objects;
@@ -39,13 +38,6 @@ public class ChannelBindException extends RuntimeException {
3938
*/
4039
public static ChannelBindException fail(SocketAddress bindAddress, @Nullable Throwable cause) {
4140
Objects.requireNonNull(bindAddress, "bindAddress");
42-
if (cause instanceof java.net.BindException ||
43-
// With epoll/kqueue transport it is
44-
// io.netty.channel.unix.Errors$NativeIoException: bind(..) failed: Address already in use
45-
(cause instanceof IOException && cause.getMessage() != null &&
46-
cause.getMessage().contains("bind(..)"))) {
47-
cause = null;
48-
}
4941
if (!(bindAddress instanceof InetSocketAddress)) {
5042
return new ChannelBindException(bindAddress.toString(), cause);
5143
}

reactor-netty-core/src/test/java/reactor/netty/ChannelBindExceptionTest.java

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2021 VMware, Inc. or its affiliates, All Rights Reserved.
2+
* Copyright (c) 2021-2025 VMware, Inc. or its affiliates, All Rights Reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -28,27 +28,30 @@ class ChannelBindExceptionTest {
2828
@Test
2929
void testFailBindExceptionCause() {
3030

31-
UnsupportedOperationException cause = new UnsupportedOperationException();
31+
Exception cause = new UnsupportedOperationException();
3232
ChannelBindException ex = ChannelBindException.fail(new InetSocketAddress("test", 4956), cause);
3333
assertThat(ex.getCause()).isEqualTo(cause);
3434
assertThat(ex.localHost()).isEqualTo("test");
3535
assertThat(ex.localPort()).isEqualTo(4956);
3636

37-
ex = ChannelBindException.fail(new InetSocketAddress("test", 4956), new BindException("Address already in use"));
38-
assertThat(ex.getCause()).isEqualTo(null);
37+
cause = new BindException("Address already in use");
38+
ex = ChannelBindException.fail(new InetSocketAddress("test", 4956), cause);
39+
assertThat(ex.getCause()).isEqualTo(cause);
3940
assertThat(ex.localHost()).isEqualTo("test");
4041
assertThat(ex.localPort()).isEqualTo(4956);
4142

4243
// Not possible to mock io.netty.channel.unix.Errors.NativeIoException or create a new instance because of Jni errors
4344
// java.lang.UnsatisfiedLinkError: 'int io.netty.channel.unix.ErrorsStaticallyReferencedJniMethods.errnoENOENT()'
44-
ex = ChannelBindException.fail(new InetSocketAddress("test", 4956), new IOException("bind(..) failed: Address already in use"));
45-
assertThat(ex.getCause()).isEqualTo(null);
45+
cause = new IOException("bind(..) failed: Address already in use");
46+
ex = ChannelBindException.fail(new InetSocketAddress("test", 4956), cause);
47+
assertThat(ex.getCause()).isEqualTo(cause);
4648
assertThat(ex.localHost()).isEqualTo("test");
4749
assertThat(ex.localPort()).isEqualTo(4956);
4850

4951
// Issue-1668
50-
ex = ChannelBindException.fail(new InetSocketAddress("test", 4956), new IOException("bind(..) failed: Die Adresse wird bereits verwendet"));
51-
assertThat(ex.getCause()).isEqualTo(null);
52+
cause = new IOException("bind(..) failed: Die Adresse wird bereits verwendet");
53+
ex = ChannelBindException.fail(new InetSocketAddress("test", 4956), cause);
54+
assertThat(ex.getCause()).isEqualTo(cause);
5255
assertThat(ex.localHost()).isEqualTo("test");
5356
assertThat(ex.localPort()).isEqualTo(4956);
5457

0 commit comments

Comments
 (0)