Repository: netty/netty
Issue: Domain socket channel local address is null

### Expected behavior

The domain socket local address is not null. 

### Actual behavior

The domain socket local address is null. 

`QueueDomainSocketChannel#localAddress0()` returns `local` field which has never been set before (other than null at construction time and in `doConnect`). It should reflect the value in the file descriptor `fd` field instead.

### Steps to reproduce

Create a client domain socket (bsd or epoll) connect to a server, then get the local channel address.

### Netty version

[4.1.92.Final,)


Issue comments:
thanks @violetagg 

Pull request review comments:

Patch that resolved the issue:
diff --git a/transport-classes-epoll/src/main/java/io/netty/channel/epoll/EpollDomainSocketChannel.java b/transport-classes-epoll/src/main/java/io/netty/channel/epoll/EpollDomainSocketChannel.java
index 0773e39133a..b72dd69fa5e 100644
--- a/transport-classes-epoll/src/main/java/io/netty/channel/epoll/EpollDomainSocketChannel.java
+++ b/transport-classes-epoll/src/main/java/io/netty/channel/epoll/EpollDomainSocketChannel.java
@@ -87,7 +87,7 @@ public EpollDomainSocketChannelConfig config() {
     @Override
     protected boolean doConnect(SocketAddress remoteAddress, SocketAddress localAddress) throws Exception {
         if (super.doConnect(remoteAddress, localAddress)) {
-            local = (DomainSocketAddress) localAddress;
+            local = localAddress != null ? (DomainSocketAddress) localAddress : socket.localDomainSocketAddress();
             remote = (DomainSocketAddress) remoteAddress;
             return true;
         }
diff --git a/transport-classes-kqueue/src/main/java/io/netty/channel/kqueue/KQueueDomainSocketChannel.java b/transport-classes-kqueue/src/main/java/io/netty/channel/kqueue/KQueueDomainSocketChannel.java
index 6e99e9c3e63..6b5ee22900c 100644
--- a/transport-classes-kqueue/src/main/java/io/netty/channel/kqueue/KQueueDomainSocketChannel.java
+++ b/transport-classes-kqueue/src/main/java/io/netty/channel/kqueue/KQueueDomainSocketChannel.java
@@ -80,7 +80,7 @@ public KQueueDomainSocketChannelConfig config() {
     @Override
     protected boolean doConnect(SocketAddress remoteAddress, SocketAddress localAddress) throws Exception {
         if (super.doConnect(remoteAddress, localAddress)) {
-            local = (DomainSocketAddress) localAddress;
+            local = localAddress != null ? (DomainSocketAddress) localAddress : socket.localDomainSocketAddress();
             remote = (DomainSocketAddress) remoteAddress;
             return true;
         }


Test patch:
diff --git a/testsuite/src/main/java/io/netty/testsuite/transport/socket/SocketAddressesTest.java b/testsuite/src/main/java/io/netty/testsuite/transport/socket/SocketAddressesTest.java
index ecab824f887..dce8c082bd1 100644
--- a/testsuite/src/main/java/io/netty/testsuite/transport/socket/SocketAddressesTest.java
+++ b/testsuite/src/main/java/io/netty/testsuite/transport/socket/SocketAddressesTest.java
@@ -39,14 +39,25 @@ public void testAddresses(TestInfo testInfo) throws Throwable {
         run(testInfo, new Runner<ServerBootstrap, Bootstrap>() {
             @Override
             public void run(ServerBootstrap serverBootstrap, Bootstrap bootstrap) throws Throwable {
-                testAddresses(serverBootstrap, bootstrap);
+                testAddresses(serverBootstrap, bootstrap, true);
+            }
+        });
+    }
+
+    @Test
+    @Timeout(value = 30000, unit = TimeUnit.MILLISECONDS)
+    public void testAddressesConnectWithoutLocalAddress(TestInfo testInfo) throws Throwable {
+        run(testInfo, new Runner<ServerBootstrap, Bootstrap>() {
+            @Override
+            public void run(ServerBootstrap serverBootstrap, Bootstrap bootstrap) throws Throwable {
+                testAddresses(serverBootstrap, bootstrap, false);
             }
         });
     }
 
     protected abstract void assertAddress(SocketAddress address);
 
-    private void testAddresses(ServerBootstrap sb, Bootstrap cb) throws Throwable {
+    private void testAddresses(ServerBootstrap sb, Bootstrap cb, boolean withLocalAddress) throws Throwable {
         Channel serverChannel = null;
         Channel clientChannel = null;
         try {
@@ -65,7 +76,11 @@ public void channelActive(ChannelHandlerContext ctx) {
             assertNull(clientChannel.localAddress());
             assertNull(clientChannel.remoteAddress());
 
-            clientChannel.connect(serverChannel.localAddress(), newSocketAddress()).syncUninterruptibly().channel();
+            if (withLocalAddress) {
+                clientChannel.connect(serverChannel.localAddress(), newSocketAddress()).syncUninterruptibly().channel();
+            } else {
+                clientChannel.connect(serverChannel.localAddress()).syncUninterruptibly().channel();
+            }
 
             assertAddress(clientChannel.localAddress());
             assertAddress(clientChannel.remoteAddress());