Skip to content

Commit dd5955d

Browse files
committed
Corrects behaviour which was returning null when config and credentials files were not found for profiles. Now it returns an empty map, as it used to
1 parent a8c7d39 commit dd5955d

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
# __2.20.52__ __2023-04-24__
2+
## __Profile Files, Core__
3+
- ### Bugfixes
4+
- The fix avoids a NullPointerException when calling the profiles() method
5+
on a ProfileFile object, whose config/credentials files were not found in ~/.aws.
6+
An empty map is returned instead, as in previous versions.
7+
18
# __2.20.51__ __2023-04-21__
29
## __AWS SDK for Java v2__
310
- ### Features

core/profiles/src/main/java/software/amazon/awssdk/profiles/ProfileFile.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ public Optional<Profile> profile(String profileName) {
117117
*/
118118
public Map<String, Profile> profiles() {
119119
Map<String, Profile> profileMap = profilesAndSectionsMap.get(PROFILES_SECTION_TITLE);
120-
return profileMap != null ? Collections.unmodifiableMap(profileMap) : profileMap;
120+
return profileMap != null ? Collections.unmodifiableMap(profileMap) : Collections.emptyMap();
121121
}
122122

123123
@Override

core/profiles/src/test/java/software/amazon/awssdk/profiles/ProfileFileTest.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -554,6 +554,15 @@ public void loadingDefaultProfileFileWorks() {
554554
ProfileFile.defaultProfileFile();
555555
}
556556

557+
@Test
558+
public void returnsEmptyMap_when_AwsFilesDoNotExist() {
559+
ProfileFile missingProfile = ProfileFile.aggregator()
560+
.build();
561+
562+
assertThat(missingProfile.profiles()).isEmpty();
563+
assertThat(missingProfile.profiles()).isInstanceOf(Map.class);
564+
}
565+
557566
private ProfileFile configFile(String configFile) {
558567
return ProfileFile.builder()
559568
.content(new StringInputStream(configFile))

0 commit comments

Comments
 (0)