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

NullPointerException crash in LottieComposition.getLayers() #1958

Closed
chinalwb opened this issue Dec 10, 2021 · 1 comment
Closed

NullPointerException crash in LottieComposition.getLayers() #1958

chinalwb opened this issue Dec 10, 2021 · 1 comment
Milestone

Comments

@chinalwb
Copy link
Contributor

chinalwb commented Dec 10, 2021

Describe the bug
Race condition caused NPE.

See the exception stack below:

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)
       at com.airbnb.lottie.LottieDrawable.setComposition(LottieDrawable.java:216)
       at com.airbnb.lottie.LottieAnimationView.setComposition(LottieAnimationView.java:504)
       at com.airbnb.lottie.LottieAnimationView$2.onResult(LottieAnimationView.java:81)
       at com.airbnb.lottie.LottieAnimationView$2.onResult(LottieAnimationView.java:79)
       at com.airbnb.lottie.LottieTask.notifySuccessListeners(LottieTask.java:144)
       at com.airbnb.lottie.LottieTask.access$100(LottieTask.java:27)
       at com.airbnb.lottie.LottieTask$1.run(LottieTask.java:131)
       at android.os.Handler.handleCallback(Handler.java:938)
       at android.os.Handler.dispatchMessage(Handler.java:99)
       at android.os.Looper.loop(Looper.java:246)
       at android.app.ActivityThread.main(ActivityThread.java:8595)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:602)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130)

This is a race condition issue so not always reproducible.

I was using version 3.4.1, but I checked the code in master branch, the key part to this issue keeps the same between version 3.4.1 and the latest version 4.2.2.

Steps To Reproduce
Race condition issue, there is no fix steps to reproduce.

See the issue analysis in PR #1959 .

@gpeal gpeal closed this as completed Dec 13, 2021
gpeal pushed a commit that referenced this issue 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
@WilbertClark
Copy link

WilbertClark commented Dec 14, 2021 via email

@gpeal gpeal added this to the 4.0 milestone Jan 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants