react-native-image-picker: testOnImmutable fails with java.lang.NullPointerException
Description
testOnImmutable() in ImageConfigTest.java throws NPE at line 29: ImageConfig updated = original.withOriginalFile(null);.
withOriginalFile has a @Nullable annotation for the parameter - but I think the subsequent line String extension = MimeTypeMap.getFileExtensionFromUrl(original.getAbsolutePath()); causes NPE.
This test failure causes gradlew build or gradlew assembleRelease to fail on an app that uses this package.
How to repeat issue and example
- Install react-native-image-picker per README instructions.
- Import to app using
import ImagePicker from 'react-native-image-picker';. Use in app (my example is here) - Run
./gradlew buildor./gradlew assembleReleasefrom the android folder of the app
Will get the following error during build:
> Task :react-native-image-picker:testDebugUnitTest
com.imagepicker.testing.media.ImageConfigTest > testOnImmutable FAILED
java.lang.NullPointerException at ImageConfigTest.java:29
5 tests completed, 1 failed
FAILURE: Build failed with an exception.
Solution
Opened PR #973 . I worked around using the following change in ImageConfig.java - please let me know if there’s a better way to handle this:
public @NonNull ImageConfig withOriginalFile(@Nullable final File original)
{
if (original != null) {
//if it is a GIF file, always set quality to 100 to prevent compression
String extension = MimeTypeMap.getFileExtensionFromUrl(original.getAbsolutePath());
int quality = this.quality;
if(extension.contains("gif")){
quality = 100;
}
}
return new ImageConfig(
original, this.resized, this.maxWidth,
this.maxHeight, quality, this.rotation,
this.saveToCameraRoll
);
}
Additional Information
- React Native version: 0.57.4
- Platform: Android
- Development Operating System: Ubuntu 18.04
- Dev tools: react-native-cli
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 17 (1 by maintainers)
Commits related to this issue
- #972: change ImageConfig.withOriginalFile() to address testOnImmutable failure — committed to sometimescasey/react-native-image-picker by sometimescasey 6 years ago
- #972: change ImageConfig.withOriginalFile() to address testOnImmutable failure (#973) — committed to react-native-image-picker/react-native-image-picker by sometimescasey 5 years ago
- Merge tag 'v0.28.0' of https://github.com/react-native-community/react-native-image-picker 0.28.0 * tag 'v0.28.0' of https://github.com/react-native-community/react-native-image-picker: 0.28.0 R... — committed to s-chernomorets/react-native-image-picker by s-chernomorets 5 years ago
- Merge branch 'master' into patch-update-0.27.1-0.28.0 * master: 0.28.0 Revert "[iOS] Update permissions flow for iOS 11 UIImagePickerController (#819)" Update Reference.md Set value for key "... — committed to s-chernomorets/react-native-image-picker by s-chernomorets 5 years ago
- Merge remote-tracking branch 'theoriginal/master' into feature/plp * theoriginal/master: (51 commits) 0.28.1 Export the interfaces in TypeScript (#1042) 0.28.0 Revert "[iOS] Update permission... — committed to 3sidedcube/react-native-image-picker by deleted user 5 years ago
@spsaucier-bakkt I found that, with a device attached, setup for USB debugging, and listed in
add devicessimply runningreact-native run-androidworks (no--deviceIdflag). There is something about the--deviceIdflag that causes problems.While this certainly isn’t a fix, I hope this helps you all test on devices!
This issue still happens when attempting to build a APK. Not sure why it was closed. This library prevents my application from building:
Follow up
I got this working. The steps I took were (all from my project root):
rm -rf android/buildrm -rf android/app/build(we have some custom Android modules)rm -rf ./node_modules/npm it(to install all project dependencies and run our tests)npx react-native start(we use npx to avoid having to install global node modules)npx react-native run-android --deviceId $DEVICE_IDI’m guessing that at some point something got out of sync. Blowing everything away and starting from scratch seems to have fixed the issue! 🤘
I randomly found this thread on flutter which apparently had the same issue: https://github.com/flutter/flutter/issues/48943#issuecomment-575014355
Flutter fixed it here: https://github.com/flutter/plugins/pull/2475.
Looks like we need to bump roboelectric? cc @janicduplessis since you originally fixed the issue.
I have the same issue on version 0.27.2
But on 0.26.10 everything works fine