Skip to content

Fix NPE when a rewarded video without ClickThrough or end card ends its countdown - #1031

Merged
mdanylov-sigma merged 2 commits into
prebid:masterfrom
floxis-admin:fix/rewarded-video-missing-learn-more
Oct 18, 2026
Merged

mdanylov-sigma merged 2 commits into
prebid:masterfrom
floxis-admin:fix/rewarded-video-missing-learn-more

Conversation

@floxis-admin

@floxis-admin floxis-admin commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Problem

A rewarded video rendered by Prebid crashes the app when its VAST has no ClickThrough and no companion ad. The crash is a NullPointerException on the main thread, raised when the reward countdown ends:

java.lang.NullPointerException: Cannot invoke "android.view.View.setVisibility(int)" because "learnMore" is null
    at org.prebid.mobile.rendering.views.interstitial.InterstitialVideo$3.onFinish(InterstitialVideo.java:442)
  1. InterstitialVideo.showDurationTimer ends the rewarded countdown by calling findViewById(R.id.tv_learn_more).setVisibility(VISIBLE) whenever the ad has no end card.
  2. The learn-more view is added only by VideoCreative.showCallToAction, which runs only when the VAST has a ClickThrough. hasEndCard is true only when there is a companion.
  3. stopCountDownTimer() also calls onFinish(). pauseVideo() calls stopCountDownTimer() whenever the interstitial loses window focus, for example from the notification shade or the home button, so the same crash happens mid-video. On a device, pressing home one second into such a video crashes with pauseVideo → stopCountDownTimer → onFinish in the stack trace.

I reproduced it on 3.3.4, 3.4.0 and master through the AdMob adapter, on an API 34 emulator and on a physical device. The VAST was an InLine Linear ad with a MediaFile and no VideoClicks/ClickThrough and no CompanionAds. The app crashes when the countdown ends.

Fix

Show the learn-more view only if it exists. Nothing changes for a VAST that has a ClickThrough or an end card.

Tests

New Robolectric test, InterstitialVideoRewardedCountdownTest:

  • countdown end without a learn-more view or an end card (threw before the fix)
  • pause without a learn-more view or an end card (threw before the fix)
  • learn-more view shown when it exists
  • learn-more view kept hidden when there is an end card

./gradlew PrebidMobile-core:testReleaseUnitTest passes.

…ts countdown

InterstitialVideo's rewarded countdown shows the learn-more view when it finishes and the ad has no end card. That view is only added when the VAST has a ClickThrough, so a rewarded VAST with neither a ClickThrough nor a companion threw a NullPointerException on the main thread. The countdown finishes when it runs out and also when the video is paused, so losing window focus mid-video crashed the same way.

The learn-more view is now shown only when it exists.
@floxis-admin

Copy link
Copy Markdown
Contributor Author

@mdanylov-sigma could you approve the workflow run for this PR? Its checks are waiting for maintainer approval as a first-time contribution.

One more data point since opening: most rewarded demand we see arrives as VAST wrappers, and a wrapper chain that ends in an InLine with no ClickThrough and no companion takes the same path, so the crash is not limited to inline VAST. The fix applies unchanged, because the countdown reads the resolved creative.

@mdanylov-sigma mdanylov-sigma left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the detailed repro and the stack traces.

I don't think this reproduces on 3.3.4. There, VideoCreative.showCallToAction still had else if (isRewarded) videoCreativeView.showCallToAction(false), so every rewarded video got a hidden learn-more view and this lookup couldn't return null. #987 removed that branch, so the crash is a 3.4.0 regression. Could you recheck 3.3.4 and update the description?

One more thing outside the diff: countDownTimer isn't nulled after it finishes, and onDetachedFromWindow, close() and InterstitialView.destroy() never cancel it. So onFinish runs again on every later focus loss. If the ad is closed before the countdown ends (the reward time can be longer than the video), the timer keeps running and holds the dialog and its views until it finishes. Not a blocker for this PR, but worth a follow-up.

Comment on lines 440 to 446
if (isRewarded && !hasEndCard) {
// Only a VAST with a ClickThrough has a learn-more view.
View learnMore = adViewContainer.findViewById(R.id.tv_learn_more);
learnMore.setVisibility(View.VISIBLE);
if (learnMore != null) {
learnMore.setVisibility(View.VISIBLE);
}
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The guard fixes the crash, but since #987 this block does nothing in production. With a ClickThrough, VideoCreativeView.addCallToActionView adds the learn-more view already VISIBLE, so this setVisibility is a no-op. Without one, the view doesn't exist. Nothing creates a hidden learn-more view any more.

#987 shows the CTA on rewarded ads from the start on purpose (#982), so I'd delete the whole if rather than guard it. That also drops the isRewarded && check, which is always true here because showDurationTimer only runs for rewarded ads.

Comment on lines +101 to +107
private View addHiddenLearnMore() {
View learnMore = new View(activity);
learnMore.setId(R.id.tv_learn_more);
learnMore.setVisibility(View.GONE);
adViewContainer.addView(learnMore);
return learnMore;
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This builds a state the app no longer creates: a GONE learn-more view sitting directly in the container. Since #987 the real view is added VISIBLE inside VideoCreativeView, even when there's an end card. So countdownFinishes_WithEndCard_KeepsLearnMoreHidden passes, but in the app a rewarded ad with an end card and a ClickThrough shows Learn More for the whole video. If the block goes away (see the comment on InterstitialVideo), I'd drop these two tests and keep the two no-crash ones.


interstitialVideo.pauseVideo();

assertEquals(0, adViewContainer.getChildCount());

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small one: this asserts that pausing removes the countdown circle. That happens only because stopCountDownTimer() calls onFinish(). If someone later stops pause from finishing the countdown, this test fails even though that's the right fix. Could it just check that pauseVideo() doesn't throw?

AdUnitConfiguration config = mock(AdUnitConfiguration.class);
when(config.isRewarded()).thenReturn(true);

interstitialVideo = new InterstitialVideo(activity, adViewContainer, interstitialManager, config);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Each InterstitialVideo starts a java.util.Timer thread in init(), and showDurationTimer starts a CountDownTimer. Only the pause test cancels them. Could you add a teardown?

@After
public void tearDown() {
    interstitialVideo.pauseVideo();
}

Since prebid#987 the learn-more view is added visible when the VAST has a ClickThrough and not at all otherwise, so the countdown's setVisibility call either did nothing or hit a missing view. Drop the block instead of guarding it, and trim the tests to the two no-crash cases.
@mdanylov-sigma
mdanylov-sigma self-requested a review October 18, 2026 18:02
@mdanylov-sigma
mdanylov-sigma merged commit d0327c8 into prebid:master Oct 18, 2026
6 checks passed
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