by commandlinefan · 4y ago · 0 comments
Actually, my experience is the opposite - they check like hell, all over the place, reflexively, because a null pointer exception is a blaring emergency that has to be fixed RIGHT NOW, so I always see Java code written like this:
if (customer != null && customer.getOrder() != null && customer.getOrder().getLineItemList() != null) {
for (LineItem item : customer.getOrder().getLineItemList()) {
if (item.getProduct() != null && item.getProduct().getPrice() != null && item.getProduct().getPrice().getCurrency() != null) {
...
} // else don't do anything, don't even log an error, just continue on as if an empty product or price object is an ignorable error and create a much harder to diagnose problem than a null pointer exceptioncustomer?.order?.lineItemList?.forEach { item -> val currency = item?.product?.price?.currency