Skip to content

Commit 246136c

Browse files
authored
Fixing nullability issue of message and adding test coverage (#5907)
* Fixing nullability issue of message and adding test coverage * Adding Changelog * Fixed changelog message --------- Co-authored-by: Ran Vaknin <[email protected]>
1 parent 95b30dc commit 246136c

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"type": "bugfix",
3+
"category": "AWS SDK for Java v2",
4+
"contributor": "",
5+
"description": "Fixed an issue in AwsServiceException#getMessage() where it returned an empty string instead of null when the message is null."
6+
}

core/aws-core/src/main/java/software/amazon/awssdk/awscore/exception/AwsServiceException.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ public String getMessage() {
7979
joiner.add(diagnostics.toString());
8080
}
8181

82-
return joiner.toString();
82+
String result = joiner.toString();
83+
return result.isEmpty() ? super.getMessage() : result;
8384
}
8485

8586
private String serviceDiagnostics() {

core/aws-core/src/test/java/software/amazon/awssdk/awscore/exception/AwsServiceExceptionTest.java

+26
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,32 @@ private static Stream<Arguments> exceptionMessageTestCases() {
122122
);
123123
}
124124

125+
@ParameterizedTest
126+
@MethodSource("messageNullabilityTestCases")
127+
void getMessage_respectsNullBehavior(String testDescription,
128+
AwsServiceException.Builder builder,
129+
String expectedMessage) {
130+
AwsServiceException e = builder.build();
131+
assertThat(e.getMessage())
132+
.as(testDescription)
133+
.isEqualTo(expectedMessage);
134+
}
135+
136+
private static Stream<Arguments> messageNullabilityTestCases() {
137+
return Stream.of(
138+
Arguments.of(
139+
"No message or details set",
140+
AwsServiceException.builder(),
141+
null
142+
),
143+
Arguments.of(
144+
"Explicitly null message without details",
145+
AwsServiceException.builder().message(null),
146+
null
147+
)
148+
);
149+
}
150+
125151
@Test
126152
public void exceptionMessage_withoutErrorMessage() {
127153
AwsServiceException e = AwsServiceException.builder()

0 commit comments

Comments
 (0)