Skip to content

Fix potential NPE when checking transform identity with null startValue - #2690

Open
Nepomuk5665 wants to merge 1 commit into
airbnb:masterfrom
Nepomuk5665:fix-npe-animatable-transform-parser
Open

Nepomuk5665 wants to merge 1 commit into
airbnb:masterfrom
Nepomuk5665:fix-npe-animatable-transform-parser

Conversation

@Nepomuk5665

Copy link
Copy Markdown

Summary

This PR fixes a potential NullPointerException in AnimatableTransformParser.java when checking if transform values are identity transforms.

The Bug

The identity check methods (isAnchorPointIdentity, isPositionIdentity, isRotationIdentity, isScaleIdentity, isSkewIdentity, isSkewAngleIdentity) were accessing Keyframe.startValue without null checks, but startValue is annotated as @Nullable in Keyframe.java:

@Nullable public final T startValue;

This would cause a NullPointerException when:

  1. For PointF values (anchorPoint, position): calling .equals() on null
  2. For Float values (rotation, skew, skewAngle): auto-unboxing null to float
  3. For ScaleXY values (scale): calling .equals() on null

Evidence That Null Values Are Expected

The existence of ensureValidRotationKeyframes() method in the same file explicitly checks for and handles null startValue:

} else if (rotation.getKeyframes().get(0).startValue == null) {
  rotation.getKeyframes().set(0, new Keyframe<>(...));
}

This demonstrates that null values can occur in practice from certain animation exports.

The Fix

Added explicit null checks before accessing startValue in all identity check methods. If startValue is null, the transform is treated as non-identity, which is the safe default behavior that preserves the transform data in the parsed result.

Testing

The fix is straightforward null-safety improvement. The behavior is:

  • If startValue is null, return false (not identity) instead of crashing
  • If startValue is not null, behavior is unchanged

The identity check methods in AnimatableTransformParser were accessing
Keyframe.startValue without null checks, but startValue is annotated as
@nullable and can be null in certain animation exports. This would cause
a NullPointerException when:

1. For PointF values (anchorPoint, position): calling .equals() on null
2. For Float values (rotation, skew, skewAngle): auto-unboxing null to float
3. For ScaleXY values (scale): calling .equals() on null

The existence of ensureValidRotationKeyframes() method that explicitly
checks for null startValue demonstrates that null values are expected.

This fix adds explicit null checks before accessing startValue in all
identity check methods, treating null startValue as non-identity (which
is the safe default behavior).
@github-actions

Copy link
Copy Markdown

Snapshot Tests
API 23: Report Diff
API 35: Report Diff

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