Skip to content

Commit

Permalink
Allow null sender when using DatagramPacketEncoder
Browse files Browse the repository at this point in the history
Motivation:

It is valid to use null as sender so we should support it when DatagramPacketEncoder checks if it supports the message.

Modifications:

- Add null check
- Add unit test

Result:

Fixes #9199.
  • Loading branch information
normanmaurer committed May 31, 2019
1 parent ec69da9 commit 95b361f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public boolean acceptOutboundMessage(Object msg) throws Exception {
@SuppressWarnings("rawtypes")
AddressedEnvelope envelope = (AddressedEnvelope) msg;
return encoder.acceptOutboundMessage(envelope.content())
&& envelope.sender() instanceof InetSocketAddress
&& (envelope.sender() instanceof InetSocketAddress || envelope.sender() == null)
&& envelope.recipient() instanceof InetSocketAddress;
}
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,17 @@ public void tearDown() {

@Test
public void testEncode() {
testEncode(false);
}

@Test
public void testEncodeWithSenderIsNull() {
testEncode(true);
}

private void testEncode(boolean senderIsNull) {
InetSocketAddress recipient = SocketUtils.socketAddress("127.0.0.1", 10000);
InetSocketAddress sender = SocketUtils.socketAddress("127.0.0.1", 20000);
InetSocketAddress sender = senderIsNull ? null : SocketUtils.socketAddress("127.0.0.1", 20000);
assertTrue(channel.writeOutbound(
new DefaultAddressedEnvelope<String, InetSocketAddress>("netty", recipient, sender)));
DatagramPacket packet = channel.readOutbound();
Expand Down

0 comments on commit 95b361f

Please sign in to comment.