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 few potential NPE race conditions #1917

Merged
merged 1 commit into from
Nov 3, 2021
Merged

Fix a few potential NPE race conditions #1917

merged 1 commit into from
Nov 3, 2021

Conversation

gpeal
Copy link
Collaborator

@gpeal gpeal commented Oct 7, 2021

Although me and the reporters are unable to reproduce these NPEs, it's not impossible that they would occur if either:

  • LottieDrawable's composition is set multiple times from multiple threads
  • Dynamic properties are set from multiple threads
    This adds some thread safety to variable access and should resolve these.

Fixes #1794

@LottieSnapshotBot
Copy link

Snapshot Tests
28: Report Diff

@LottieSnapshotBot
Copy link

@gpeal gpeal merged commit 156e485 into master Nov 3, 2021
@gpeal gpeal deleted the gpeal/npe-1794 branch November 3, 2021 05:20
This was referenced Nov 21, 2021
gpeal pushed a commit that referenced this pull request Dec 13, 2021
This PR addresses the issue #1958 , although the crash is pretty hard to reproducible, 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
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.

Null pointer crash
2 participants