Repository navigation
Fix NPE when a rewarded video without ClickThrough or end card ends its countdown - #1031
Conversation
…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.
|
@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 |
mdanylov-sigma
left a comment
There was a problem hiding this comment.
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.
| 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); | ||
| } | ||
| } |
There was a problem hiding this comment.
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.
| private View addHiddenLearnMore() { | ||
| View learnMore = new View(activity); | ||
| learnMore.setId(R.id.tv_learn_more); | ||
| learnMore.setVisibility(View.GONE); | ||
| adViewContainer.addView(learnMore); | ||
| return learnMore; | ||
| } |
There was a problem hiding this comment.
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()); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
Problem
A rewarded video rendered by Prebid crashes the app when its VAST has no
ClickThroughand no companion ad. The crash is aNullPointerExceptionon the main thread, raised when the reward countdown ends:InterstitialVideo.showDurationTimerends the rewarded countdown by callingfindViewById(R.id.tv_learn_more).setVisibility(VISIBLE)whenever the ad has no end card.VideoCreative.showCallToAction, which runs only when the VAST has a ClickThrough.hasEndCardis true only when there is a companion.stopCountDownTimer()also callsonFinish().pauseVideo()callsstopCountDownTimer()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 withpauseVideo→stopCountDownTimer→onFinishin 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/ClickThroughand noCompanionAds. 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:./gradlew PrebidMobile-core:testReleaseUnitTestpasses.