question

wsadiq avatar image
wsadiq asked Dan commented

Null pointer while getting item quantity

We have a native app on Clover. At one point in the app, we are trying to get quantity of line item and getting a null pointer exception.

List<LineItem> items = order.getLineItems();
for (LineItem item : items) {
     long qty = item.hasUnitQty() ? item.getUnitQty() : 1000;
}
In the above code, Order has been obtained using OrderConnector. The line that gets the item's quantity is generating a null pointer exception. Can anybody help explain what is wrong here?

Thanks in advance.
OrdersLineItems
2 comments
10 |2000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

wsadiq avatar image wsadiq commented ·

I forgot to add, this is happening for only one of our merchants - not everybody. Furthermore, this started happening only about a week ago and our app has not been updated for over a month. So obviosuly this has something to do with the merchant's invenmtory but I cannot figure out what.

0 Likes 0 ·
wsadiq avatar image wsadiq commented ·

Hello. Can anybody help? This has become an urgent issue so any help from Clover's app developer support team will be greatly appreciated.

0 Likes 0 ·

1 Answer

·
Dan avatar image
Dan answered Dan commented
It looks like LineItem#isNotNullUnitQty() is what you want.

/** Checks whether the 'unitQty' field has been set, however the value could be null */
public boolean hasUnitQty() {
return genClient.cacheHasKey(CacheKey.unitQty);
}

/** Checks whether the 'unitQty' field is set and is not null */
public boolean isNotNullUnitQty() {
return genClient.cacheValueIsNotNull(CacheKey.unitQty);
}
2 comments
10 |2000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

wsadiq avatar image wsadiq commented ·

Ok. Thanks. Has anything changed. Our application has not been updated since February but some merchants just started getting this null pointer error in the last 2-3 weeks. SO I am a little puzzled as to what may have changed to suddenly cause this exception.

0 Likes 0 ·
Dan avatar image Dan ♦ wsadiq commented ·

No changes to the has/isNotNull behavior that I know of. I don't know if it started being explicitly set to null by a first or third party app. Given that it is only impacting one merchant, I'd guess that either a third party app, specific flow/item configuration etc why this is surfacing now.

0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Welcome to the
Clover Developer Community