Skip to content

Commit adb5b7d

Browse files
authored
Merge pull request #57 from Iterable/bugfix/ITBL-6071-push-open-noninit-fix
Fix a NullPointerException when SDK isn't initialized in Application#onCreate
2 parents a52af2a + 93ddfbe commit adb5b7d

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

iterableapi/src/main/java/com/iterable/iterableapi/IterableApi.java

+5
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,11 @@ public IterableAttributionInfo getAttributionInfo() {
111111
* @param attributionInfo Attribution information object
112112
*/
113113
void setAttributionInfo(IterableAttributionInfo attributionInfo) {
114+
if (_applicationContext == null) {
115+
IterableLogger.e(TAG, "setAttributionInfo: Iterable SDK is not initialized with a context.");
116+
return;
117+
}
118+
114119
IterableUtil.saveExpirableJsonObject(
115120
getPreferences(),
116121
IterableConstants.SHARED_PREFS_ATTRIBUTION_INFO_KEY,

iterableapi/src/test/java/com/iterable/iterableapi/IterablePushActionReceiverTest.java

+13
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,19 @@ private void stubAnyRequestReturningStatusCode(int statusCode, String body) {
6161
server.enqueue(response);
6262
}
6363

64+
@Test
65+
public void testPushOpenWithNonInitializedSDK() throws Exception {
66+
stubAnyRequestReturningStatusCode(200, "{}");
67+
IterableApi.sharedInstance = new IterableApi();
68+
IterablePushActionReceiver iterablePushActionReceiver = new IterablePushActionReceiver();
69+
Intent intent = new Intent(IterableConstants.ACTION_PUSH_ACTION);
70+
intent.putExtra(IterableConstants.ITERABLE_DATA_ACTION_IDENTIFIER, "silentButton");
71+
intent.putExtra(IterableConstants.ITERABLE_DATA_KEY, IterableTestUtils.getResourceString("push_payload_silent_action.json"));
72+
73+
// This must not crash
74+
iterablePushActionReceiver.onReceive(RuntimeEnvironment.application, intent);
75+
}
76+
6477
@Test
6578
public void testTrackPushOpenWithCustomAction() throws Exception {
6679
final JSONObject responseData = new JSONObject("{\"key\":\"value\"}");

0 commit comments

Comments
 (0)