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 if LottieValueCallback returns null. #2422

Closed
idunnololz opened this issue Nov 30, 2023 · 0 comments · Fixed by #2434
Closed

NullPointerException if LottieValueCallback returns null. #2422

idunnololz opened this issue Nov 30, 2023 · 0 comments · Fixed by #2434

Comments

@idunnololz
Copy link

idunnololz commented Nov 30, 2023

Describe the bug
LottieValueCallback is allowed to return null to indicate the default value should be used as it's documentation states (

public T getValue(LottieFrameInfo<T> frameInfo) {
).

The commit a808c3f introduced a crash.

The offending commit adds the following code to SolidLayer.java:

if (colorAnimation != null) {
  paint.setColor(colorAnimation.getValue());
}

colorAnimation can be backed by a LottieValueCallback. Thus colorAnimation.getValue() can return null. When this happens
paint.setColor(colorAnimation.getValue()); will crash with a NPE as it tries to dereference a null boxed type (Integer).

What version of Lottie did you test this on?
v6.2.0.

What version of Android did you test this on?
This crash occurs on all versions of Android that Lottie supports.

Steps To Reproduce
Steps to reproduce the behavior:

  1. Add a LottieAnimationView to any screen.
  2. Add a color value callback to the LottieAnimationView that just returns null for the value. Eg. (kotlin)
      myLottieAnimationView.addValueCallback(
        KeyPath("**"),
        LottieProperty.COLOR,
        object : LottieValueCallback<Int>() {
          override fun getValue(frameInfo: LottieFrameInfo<Int>?): Int? {
            return null
          }
        },
      )
  1. Load any lottie file with a solid layer. I've attached an example lottie file here:
    lottie.json
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant