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

Fix a potential NPE race conditions #1959

Merged
merged 1 commit into from Dec 13, 2021
Merged

Fix a potential NPE race conditions #1959

merged 1 commit into from Dec 13, 2021

Conversation

chinalwb
Copy link
Contributor

@chinalwb chinalwb commented Dec 10, 2021

This PR addresses the issue #1958 , although the crash is pretty hard to reproduce, the enhancement will definitely make it more robust.

The issue was in com.airbnb.lottie.LottieDrawable#buildCompositionLayer method.
The related code is:

  private void buildCompositionLayer() {
    compositionLayer = new CompositionLayer(
        this, LayerParser.parse(composition), composition.getLayers(), composition);
    if (outlineMasksAndMattes) {
      compositionLayer.setOutlineMasksAndMattes(true);
    }
  }

The crash exception stack prints:

Fatal Exception: java.lang.NullPointerException: Attempt to invoke virtual method 'java.util.List com.airbnb.lottie.LottieComposition.getLayers()' on a null object reference
       at com.airbnb.lottie.LottieDrawable.buildCompositionLayer(LottieDrawable.java:298)
       ...

As we can see, the exception occurs at composition.getLayers(), but before executing this statement, the LayerParser.parse(composition) statement also refers to the composition object, which was fine, but after that this object had been set to null, thus caused NPE.

I think this issue is very similar to the issues resolved in PR #1917

@LottieSnapshotBot
Copy link

Snapshot Tests
28: Report Diff

@gpeal gpeal merged commit f38d0df into airbnb:master Dec 13, 2021
@airbnb airbnb deleted a comment from WilbertClark Dec 14, 2021
@gpeal gpeal modified the milestone: 4.0 Jan 10, 2022
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.

None yet

3 participants