Skip to content
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

LottieCompositionFactory: Avoid NPE when animation contains a Font Family and Context is null. #2530

Merged
merged 1 commit into from
Aug 5, 2024

Conversation

vanniktech
Copy link
Contributor

No description provided.

@vanniktech vanniktech force-pushed the fromZipStreamSyncInternal-context branch from 051a6b0 to 6caf73f Compare August 5, 2024 08:44
@@ -538,7 +538,7 @@ public static LottieResult<LottieComposition> fromZipStreamSync(@Nullable Contex
}

@WorkerThread
private static LottieResult<LottieComposition> fromZipStreamSyncInternal(Context context, ZipInputStream inputStream, @Nullable String cacheKey) {
private static LottieResult<LottieComposition> fromZipStreamSyncInternal(@Nullable Context context, ZipInputStream inputStream, @Nullable String cacheKey) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My concern here is that a lot of animations are loaded from the server and this may lead to runtime crashes where the engineer doesn't pass context and then somebody else at some point in the future sends an animation that has fonts and then it leads to crashes. It's a tough situation to recover from because they can fix it but won't be able to add the animation because it'll continue to crash older apps.

Given that this can be an application context, what is the use case in which you can't get access to at least the application context?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This crash would also happen right now with the current code that we have since the line after:

File tempFile = new File(context.getCacheDir(), fileName);

would just crash with a NPE. I just saw this and wanted to improve the behavior by at least telling you why it didn't succeed. Do you want me to throw instead of returning a LottieResult?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. IIRC, the intention here was that context is @NonNull, There is an overloaded version that omits the context parameter and clearly states in the docs that fonts will not be loaded.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clearly states in the docs that fonts will not be loaded.

This isn't the case though as it will crash.

Copy link

github-actions bot commented Aug 5, 2024

Snapshot Tests
API 23: Report Diff
API 31: Report Diff

@gpeal gpeal merged commit 1ffaac8 into airbnb:master Aug 5, 2024
7 checks passed
@vanniktech vanniktech deleted the fromZipStreamSyncInternal-context branch August 5, 2024 21:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants