0
 LineItem testItem = new LineItem("{\"createdTime\":1493752362963,\"taxRates\":{\"elements\":[{\"id\":\"H81CTR0MNB502\",\"isDefault\":true,\"name\":\"Broward Sales\",\"rate\":650000}]},\"userData\":null,\"alternateName\":\"\",\"id\":\"HWS8WYG986J58\",\"exchanged\":false,\"price\":1100,\"refunded\":false,\"binName\":null,\"isRevenue\":null,\"name\":\"Custom Item\",\"printed\":false,\"note\":null,\"itemCode\":null}");
boolean foo = testItem.getIsRevenue();
Log.d(TAG, "Initialization: " + foo);

generates a nullPointerException. The lineItem this was taken from was a simple custom item created in register.

asked 2017-05-04 08:26:18 -0500

Camp Cox Consultants gravatar image

1 answer

Sort by  
0

You are getting an NPE because you are unboxing a null.

answered 2017-05-04 10:55:33 -0500

jeff gravatar image
Comments

Except I have been told that getIsRevenue() will return true if that value is null. If you call hasIsRevenue() in that example, it returns true. Please see https://devask.clover.com/question/76... where I was told that getIsRevenue() will default to true. I am working around this with a try/catch, but this is not behaving how Sam described it, and your way doesn't make sense (since hasIsRevenue() returns true and so there is no way to tell if it has null or not since there is not a not null function for this. I am interested in what you think the official way is.

Camp Cox Consultants gravatar image
Camp Cox Consultants 2017-05-04 13:00:17 -0500

I am also interested then if you agree with Sam that the default behavior in the case of null should be that it is revenue?

Camp Cox Consultants gravatar image
Camp Cox Consultants 2017-05-04 13:01:12 -0500

BTW, This line item was created from by adding a "custom item" to the order inside register.

Camp Cox Consultants gravatar image
Camp Cox Consultants 2017-05-04 13:03:51 -0500

In your example, you create a new line item and set the value for "is revenue" to null. In that case it's going to return null. You can look at the source of the SDK and see why that is. The LineItem class is just a simple data object and doesn't encapsulate any logic about what fields can be null, or not. What the link you posted says is that in our DB, the column for "is revenue" may not be null. If you fetch an order from the server, it should return a non-null "is revenue" field.

jeff gravatar image
jeff 2017-05-05 10:42:29 -0500

The Lineitem I am using there was created by creating a custom item in register, I used the logic in the question to try to give you something to test. So, to be clear here, a custom item in register creates a lineItem where isRevenue is set to null. hasIsRevenue() returns true. I am checking to see if an item is revenue. In a previous question, Sam FROM Clover, said that getIsRevenue should return true in the case of it being null. I would be satisfied if it returned the null. Instead the call to getIsRevenue throws an exception. You are saying this is correct behavior and Sam is wrong?

Camp Cox Consultants gravatar image
Camp Cox Consultants 2017-05-05 13:21:27 -0500