Skip to content

Commit

Permalink
Do not use GalleryBucket if name is null (#894)
Browse files Browse the repository at this point in the history
Fixes #874

cursor.getString returning a null name caused the application to crash in the hashCode override function:
E AndroidRuntime: java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.String.hashCode()' on a null object reference
E AndroidRuntime: 	at com.seafile.seadroid2.cameraupload.GalleryBucketUtils$Bucket.hashCode(GalleryBucketUtils.java:51)

Reproduced and fix tested on Android 11
  • Loading branch information
fabian-z authored Jun 21, 2021
1 parent ab4c0af commit d653dee
Showing 1 changed file with 18 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ private static List<Bucket> getVideoBuckets(Context context) {
MediaStore.Video.Media.BUCKET_DISPLAY_NAME,
};
Cursor cursor = context.getContentResolver().query(images,
projection, // Which columns to return
projection, // Which columns to return
null, // Which rows to return (all rows)
null, // Selection arguments (none)
null, // Selection arguments (none)
null // Ordering
);

Expand All @@ -102,11 +102,15 @@ private static List<Bucket> getVideoBuckets(Context context) {
Bucket b = new Bucket();
b.id = cursor.getString(bucketIdColumnIndex);
b.name = cursor.getString(bucketColumnIndex);
String video_id = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Video.Media._ID));
b.videoId = video_id;
b.videoId = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Video.Media._ID));

if (b.name == null) {
continue;
}

b.isCameraBucket = false;
for (String name : CAMERA_BUCKET_NAMES) {
if (b.name != null && b.name.equalsIgnoreCase(name)) {
if (b.name.equalsIgnoreCase(name)) {
b.isCameraBucket = true;
}
}
Expand All @@ -126,9 +130,9 @@ private static List<Bucket> getImageBuckets(Context context) {
};

Cursor cursor = context.getContentResolver().query(images,
projection, // Which columns to return
projection, // Which columns to return
null, // Which rows to return (all rows)
null, // Selection arguments (none)
null, // Selection arguments (none)
null // Ordering
);

Expand All @@ -144,12 +148,16 @@ private static List<Bucket> getImageBuckets(Context context) {
Bucket b = new Bucket();
b.id = cursor.getString(bucketIdColumnIndex);
b.name = cursor.getString(bucketColumnIndex);
String image_id = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Images.Media._ID));
b.imageId = image_id;
b.imageId = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Images.Media._ID));

if (b.name == null) {
continue;
}

b.isCameraBucket = false;
b.isImages = GalleryBucketUtils.IMAGES;
for (String name : CAMERA_BUCKET_NAMES) {
if (b.name != null && b.name.equalsIgnoreCase(name)) {
if (b.name.equalsIgnoreCase(name)) {
b.isCameraBucket = true;
}
}
Expand Down

0 comments on commit d653dee

Please sign in to comment.