Skip to content

[image_picker] Move HashSet construction within if-statement #3448

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

Merged
merged 3 commits into from
Mar 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/image_picker/image_picker_android/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.8.6+2

* Fixes null pointer exception in `saveResult`.

## 0.8.6+1

* Refactors code in preparation for adopting Pigeon.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,9 @@ String retrievePendingCameraMediaUriPath() {
void saveResult(
@Nullable ArrayList<String> path, @Nullable String errorCode, @Nullable String errorMessage) {

Set<String> imageSet = new HashSet<>();
imageSet.addAll(path);
SharedPreferences.Editor editor = prefs.edit();
if (path != null) {
Set<String> imageSet = new HashSet<>(path);
editor.putStringSet(FLUTTER_IMAGE_PICKER_IMAGE_PATH_KEY, imageSet);
}
if (errorCode != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import static io.flutter.plugins.imagepicker.ImagePickerCache.SHARED_PREFERENCES_NAME;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.IsEqual.equalTo;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
Expand Down Expand Up @@ -115,4 +116,12 @@ public void imageCache_shouldBeAbleToSetAndGetQuality() {
(int) resultMapWithDefaultQuality.get(ImagePickerCache.MAP_KEY_IMAGE_QUALITY);
assertThat(defaultImageQuality, equalTo(100));
}

@Test
public void imageCache_shouldNotThrowIfPathIsNullInSaveResult() {
final ImagePickerCache cache = new ImagePickerCache(mockActivity);
cache.saveResult(null, "errorCode", "errorMessage");
assertTrue(
"No exception thrown when ImagePickerCache.saveResult() was passed a null path", true);
}
}
2 changes: 1 addition & 1 deletion packages/image_picker/image_picker_android/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: Android implementation of the image_picker plugin.
repository: https://github.com/flutter/packages/tree/main/packages/image_picker/image_picker_android
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+image_picker%22

version: 0.8.6+1
version: 0.8.6+2

environment:
sdk: ">=2.17.0 <3.0.0"
Expand Down