Skip to content

Commit 0b62ce6

Browse files
author
Niall Brennan
committed
avoid null value error
1 parent 45f2638 commit 0b62ce6

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/main/java/com/segment/analytics/android/integrations/firebase/FirebaseIntegration.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
import static com.segment.analytics.internal.Utils.hasPermission;
2828
import static com.segment.analytics.internal.Utils.isNullOrEmpty;
29+
import static java.util.Objects.isNull;
2930

3031
/**
3132
* Google Analytics for Firebase is a free app measurement solution that provides insight on app
@@ -211,7 +212,7 @@ && isNullOrEmpty(properties.currency())) {
211212
} else {
212213
property = makeKey(property);
213214
}
214-
if (property.equals(Param.ITEMS)) {
215+
if (property.equals(Param.ITEMS) && value != null) {
215216
List<ValueMap> products = properties.getList("products", ValueMap.class);
216217
ArrayList<Bundle> mappedProducts = formatProducts(products);
217218
bundle.putParcelableArrayList(property, mappedProducts);

src/test/java/com/segment/analytics/android/integration/firebase/FirebaseTest.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,23 @@ public void trackPurchaseWithProducts() {
152152
verify(firebase).logEvent(eq("purchase"), bundleEq(expected));
153153
}
154154

155+
@Test
156+
public void trackPurchaseWithNullProducts() {
157+
Properties properties = new Properties()
158+
.putValue("revenue", 100.0)
159+
.putValue("currency", "USD")
160+
.putValue("products", null);
161+
162+
integration.track(new TrackPayload.Builder().anonymousId("1234").properties(properties).event("Order Completed").build());
163+
164+
Bundle expected = new Bundle();
165+
expected.putDouble("value", 100.0);
166+
expected.putString("currency", "USD");
167+
expected.putString("items", null);
168+
169+
verify(firebase).logEvent(eq("purchase"), bundleEq(expected));
170+
}
171+
155172
@Test
156173
public void trackWithEventNameTransformation() {
157174
Properties properties = new Properties()

0 commit comments

Comments
 (0)