Skip to content

Commit

Permalink
Merge pull request #692 from prebid/680-nullpointerexception-in-reque…
Browse files Browse the repository at this point in the history
…stersendadexception

Fix for 680 NullPointerException in Requester.sendAdException
  • Loading branch information
jsligh authored Sep 29, 2023
2 parents f7a2002 + 53c8582 commit 7fc2f21
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ public BidRequester(AdUnitConfiguration config, AdRequestInput adRequestInput, R
@Override
public void startAdRequest() {
if (TextUtils.isEmpty(adConfiguration.getConfigId())) {
adResponseCallBack.onError("No configuration id specified.", 0);
if (adResponseCallBack != null) {
adResponseCallBack.onError("No configuration id specified.", 0);
}
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import org.prebid.mobile.rendering.utils.helpers.AppInfoManager;
import org.prebid.mobile.rendering.utils.helpers.ExternalViewerUtils;

import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.List;

Expand All @@ -59,6 +60,7 @@ public abstract class Requester {
protected URLBuilder urlBuilder;
protected ResponseHandler adResponseCallBack;
protected BaseNetworkTask networkTask;
protected AdIdManager.FetchAdIdInfoTask fetchAdIdInfoTask;

Requester(
AdUnitConfiguration config,
Expand Down Expand Up @@ -86,7 +88,11 @@ public void destroy() {
networkTask.destroy();
}
networkTask = null;
if (fetchAdIdInfoTask != null) {
fetchAdIdInfoTask.cancel(true);
}
adResponseCallBack = null;
fetchAdIdInfoTask = null;
}

protected List<ParameterBuilder> getParameterBuilders() {
Expand Down Expand Up @@ -125,7 +131,7 @@ protected void getAdId() {

UserConsentManager userConsentManager = ManagersResolver.getInstance().getUserConsentManager();
if (userConsentManager.canAccessDeviceData()) {
AdIdManager.initAdId(context, new AdIdFetchListener() {
fetchAdIdInfoTask = AdIdManager.initAdId(context, new AdIdFetchListener() {
@Override
public void adIdFetchCompletion() {
LogUtil.info(TAG, "Advertising id was received");
Expand All @@ -149,7 +155,9 @@ public void adIdFetchFailure() {
private void sendAdException(String logMsg, String exceptionMsg) {
LogUtil.warning(TAG, logMsg);
AdException adException = new AdException(AdException.INIT_ERROR, exceptionMsg);
adResponseCallBack.onErrorWithException(adException, 0);
if (adResponseCallBack != null) {
adResponseCallBack.onErrorWithException(adException, 0);
}
}

protected void makeAdRequest() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ private AdIdManager() {
}

// Wrap method execution in try / catch to avoid crashes in runtime if publisher didn't include identifier dependencies
public static void initAdId(final Context context, final AdIdFetchListener listener) {
public static FetchAdIdInfoTask initAdId(final Context context, final AdIdFetchListener listener) {
try {
GoogleApiAvailability apiAvailability = GoogleApiAvailability.getInstance();
int resultCode = apiAvailability.isGooglePlayServicesAvailable(context);
Expand All @@ -67,6 +67,7 @@ public static void initAdId(final Context context, final AdIdFetchListener liste
listener.adIdFetchFailure();
}
}, AD_ID_TIMEOUT_MS);
return getAdIdInfoTask;
}
else {
listener.adIdFetchCompletion();
Expand All @@ -75,6 +76,7 @@ public static void initAdId(final Context context, final AdIdFetchListener liste
catch (Throwable throwable) {
LogUtil.error(TAG, "Failed to initAdId: " + Log.getStackTraceString(throwable) + "\nDid you add necessary dependencies?");
}
return null;
}

/**
Expand All @@ -97,7 +99,7 @@ public static void setAdId(String adId) {
sAdId = adId;
}

private static class FetchAdIdInfoTask extends AsyncTask<Void, Void, Void> {
public static class FetchAdIdInfoTask extends AsyncTask<Void, Void, Void> {

private final WeakReference<Context> contextWeakReference;
private final AdIdFetchListener adIdFetchListener;
Expand Down

0 comments on commit 7fc2f21

Please sign in to comment.