Skip to content

Commit 40c70da

Browse files
Fix isHeif crash (#177944)
Fixes flutter/flutter#177942 I did not repro the crash but this looks like a pretty simple NPE that can be fixed by swapping the `.equals` order. ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. **Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). Comments from the `gemini-code-assist` bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md --------- Co-authored-by: Gray Mackall <[email protected]>
1 parent af5d3a5 commit 40c70da

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/image/Metadata.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package io.flutter.embedding.engine.image;
66

77
import androidx.annotation.NonNull;
8+
import androidx.annotation.Nullable;
89
import androidx.annotation.RequiresApi;
910
import androidx.annotation.VisibleForTesting;
1011
import io.flutter.Build;
@@ -20,7 +21,7 @@ class Metadata {
2021
int width;
2122
int height;
2223
int rotation;
23-
String mimeType;
24+
@Nullable String mimeType;
2425
int orientation;
2526
int originalHeight;
2627
int originalWidth;
@@ -52,6 +53,6 @@ static Metadata create(
5253
* @return True if the image is HEIF, false otherwise.
5354
*/
5455
boolean isHeif() {
55-
return mimeType.equals("image/heif");
56+
return "image/heif".equals(mimeType);
5657
}
5758
}

engine/src/flutter/shell/platform/android/test/io/flutter/embedding/engine/image/MetadataTest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,4 +151,11 @@ public void isHeif_returnsCorrectValue() {
151151
// Expected
152152
}
153153
}
154+
155+
@Test
156+
public void isHeif_doesNotCrashWithNullMetatdata() {
157+
Metadata metadata = new Metadata();
158+
metadata.mimeType = null;
159+
assertFalse(metadata.isHeif());
160+
}
154161
}

0 commit comments

Comments
 (0)