Skip to content

Commit 26c95da

Browse files
authored
[image_picker] Move HashSet construction within if-statement (flutter#3448)
[image_picker] Move HashSet construction within if-statement
1 parent 7636eb7 commit 26c95da

File tree

4 files changed

+15
-3
lines changed

4 files changed

+15
-3
lines changed

packages/image_picker/image_picker_android/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.8.6+2
2+
3+
* Fixes null pointer exception in `saveResult`.
4+
15
## 0.8.6+1
26

37
* Refactors code in preparation for adopting Pigeon.

packages/image_picker/image_picker_android/android/src/main/java/io/flutter/plugins/imagepicker/ImagePickerCache.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,9 @@ String retrievePendingCameraMediaUriPath() {
9696
void saveResult(
9797
@Nullable ArrayList<String> path, @Nullable String errorCode, @Nullable String errorMessage) {
9898

99-
Set<String> imageSet = new HashSet<>();
100-
imageSet.addAll(path);
10199
SharedPreferences.Editor editor = prefs.edit();
102100
if (path != null) {
101+
Set<String> imageSet = new HashSet<>(path);
103102
editor.putStringSet(FLUTTER_IMAGE_PICKER_IMAGE_PATH_KEY, imageSet);
104103
}
105104
if (errorCode != null) {

packages/image_picker/image_picker_android/android/src/test/java/io/flutter/plugins/imagepicker/ImagePickerCacheTest.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import static io.flutter.plugins.imagepicker.ImagePickerCache.SHARED_PREFERENCES_NAME;
88
import static org.hamcrest.MatcherAssert.assertThat;
99
import static org.hamcrest.core.IsEqual.equalTo;
10+
import static org.junit.Assert.assertTrue;
1011
import static org.mockito.ArgumentMatchers.any;
1112
import static org.mockito.Mockito.mock;
1213
import static org.mockito.Mockito.when;
@@ -115,4 +116,12 @@ public void imageCache_shouldBeAbleToSetAndGetQuality() {
115116
(int) resultMapWithDefaultQuality.get(ImagePickerCache.MAP_KEY_IMAGE_QUALITY);
116117
assertThat(defaultImageQuality, equalTo(100));
117118
}
119+
120+
@Test
121+
public void imageCache_shouldNotThrowIfPathIsNullInSaveResult() {
122+
final ImagePickerCache cache = new ImagePickerCache(mockActivity);
123+
cache.saveResult(null, "errorCode", "errorMessage");
124+
assertTrue(
125+
"No exception thrown when ImagePickerCache.saveResult() was passed a null path", true);
126+
}
118127
}

packages/image_picker/image_picker_android/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ description: Android implementation of the image_picker plugin.
33
repository: https://github.com/flutter/packages/tree/main/packages/image_picker/image_picker_android
44
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+image_picker%22
55

6-
version: 0.8.6+1
6+
version: 0.8.6+2
77

88
environment:
99
sdk: ">=2.17.0 <3.0.0"

0 commit comments

Comments
 (0)