-
Notifications
You must be signed in to change notification settings - Fork 910
Add null check for channel when generating error message #3574
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add null check for channel when generating error message #3574
Conversation
@zoewangg How can we move this forward? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thank you for your contribution!
ChannelDiagnostics channelDiagnostics = channel.attr(CHANNEL_DIAGNOSTICS).get(); | ||
ChannelDiagnostics parentChannelDiagnostics = channel.parent() != null ? channel.parent().attr(CHANNEL_DIAGNOSTICS).get() | ||
: null; | ||
ChannelDiagnostics channelDiagnostics, parentChannelDiagnostics; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like compilation failed.
ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project netty-nio-client: Compilation failure: Compilation failure:
NettyUtils.java:[148,12] error: variable channelDiagnostics might not have been initialized
NettyUtils.java:[151,16] error: variable parentChannelDiagnostics might not have been initialized
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be fixed now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think checkstyle still failed. Are you able to build it locally?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There were some compilation issues with NettyUtilsTest , I have fixed and updated the PR.
The builds are passing now
Kudos, SonarCloud Quality Gate passed! |
@zoewangg Can you take another look? |
Apologies for the lack of response. I think checkstyle still failed (
What JDK version are you using to build the SDK? I think there are some false positive checkstyle issues when building with JDK 18+ and we will work on fixing it. |
@@ -133,9 +133,11 @@ private static String getMessageForTooManyAcquireOperationsError() { | |||
} | |||
|
|||
public static String closedChannelMessage(Channel channel) { | |||
ChannelDiagnostics channelDiagnostics = channel.attr(CHANNEL_DIAGNOSTICS).get(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what about updating it to below code
ChannelDiagnostics channelDiagnostics = channel != null && channel.attr(CHANNEL_DIAGNOSTICS) != null ?
channel.attr(CHANNEL_DIAGNOSTICS).get() : null;
ChannelDiagnostics parentChannelDiagnostics = channel != null && channel.parent() != null ?
channel.parent().attr(CHANNEL_DIAGNOSTICS).get() : null;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That looks good to me, I added a null check for the CHANNEL_DIAGNOSTICS
attribute on the parent as well. Not sure if this passes style rules.
Can we add Junit test cases in NettyUtilTest.java @Test
public void closedChannelMessage_with_nullChannelAttribute() throws Exception {
Channel channel = Mockito.mock(Channel.class);
when(channel.parent()).thenReturn(null);
assertThat(NettyUtils.closedChannelMessage(channel))
.isEqualTo(NettyUtils.CLOSED_CHANNEL_ERROR_MESSAGE);
}
@Test
public void closedChannelMessage_with_nullChannel() throws Exception {
Channel channel = null;
assertThat(NettyUtils.closedChannelMessage(channel))
.isEqualTo(NettyUtils.CLOSED_CHANNEL_ERROR_MESSAGE);
}
@Test
public void closedChannelMessage_with_nullParentChannel() throws Exception {
Channel channel = Mockito.mock(Channel.class);
Attribute attribute = Mockito.mock(Attribute.class);
when(channel.parent()).thenReturn(null);
when(channel.attr(Mockito.any())).thenReturn(attribute);
assertThat(NettyUtils.closedChannelMessage(channel))
.isEqualTo(NettyUtils.CLOSED_CHANNEL_ERROR_MESSAGE);
} |
242a74c
to
3e21ec5
Compare
3e21ec5
to
2063abf
Compare
Kudos, SonarCloud Quality Gate passed! |
Motivation and Context
I think this issue is relevant #3435
There's a possibility of channel being null if the channel acquisition fails in this code path:
https://github.com/aws/aws-sdk-java-v2/blob/master/http-clients/netty-nio-client/src/main/java/software/amazon/awssdk/http/nio/netty/internal/NettyRequestExecutor.java#L175
Modifications
Testing
Screenshots (if appropriate)
Types of changes
Checklist
mvn install
succeedsscripts/new-change
script and following the instructions. Commit the new file created by the script in.changes/next-release
with your changes.License