Skip to content

Commit

Permalink
Fix NullPointerException when reporting mounts for mount hooks (#39022)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #39022

Fixes a possible NullPointerException thrown when trying to access the binding after the instance has been destroyed to report mounts.

I added a check for the mount item just in case 😅

Changelog: [internal]

Reviewed By: lenaic

Differential Revision: D48355738

fbshipit-source-id: 401d2e0a52b0764ed89498ecc0176d160226e509
  • Loading branch information
rubennorte authored and facebook-github-bot committed Aug 16, 2023
1 parent 67f8d40 commit 0ba9808
Showing 1 changed file with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1227,20 +1227,21 @@ public void didMountItems(@Nullable List<MountItem> mountItems) {
public void run() {
mMountNotificationScheduled.set(false);

if (mountItems == null) {
final @Nullable Binding binding = mBinding;
if (mountItems == null || binding == null) {
return;
}

// Collect surface IDs for all the mount items
List<Integer> surfaceIds = new ArrayList();
for (MountItem mountItem : mountItems) {
if (!surfaceIds.contains(mountItem.getSurfaceId())) {
if (mountItem != null && !surfaceIds.contains(mountItem.getSurfaceId())) {
surfaceIds.add(mountItem.getSurfaceId());
}
}

for (int surfaceId : surfaceIds) {
mBinding.reportMount(surfaceId);
binding.reportMount(surfaceId);
}
}
});
Expand Down

0 comments on commit 0ba9808

Please sign in to comment.