amadeus-java icon indicating copy to clipboard operation
amadeus-java copied to clipboard

Should return an empty array, empty list, or optional, instead of NULL

Open steve-donovan opened this issue 1 year ago • 2 comments

Description

As an example, the FlightOfferSearch class has an array representing Stops within a Segment. If there are no stops, the array is NULL and can cause an NPE when using java streams.

Its best practice to either return an Optional or return an empty collection to guard against NPE's.

Steps to Reproduce

  1. Make a call to Amadeus Shopping flightOffersSearch API using any available test env data
  2. Examine the returned FlightOfferSearch object. Collections, such as Stops, with no data, are returned with NULL assignment

Expected Behavior: Collections with no data should be empty, not NULL

Actual Behavior: Collections such as Stops have a NULL assignment, causing NPE when streaming is applied.

Stable Behavior? 100%

steve-donovan avatar Aug 10 '22 18:08 steve-donovan

I'm happy to make the change if you agree that it should be done

steve-donovan avatar Aug 10 '22 18:08 steve-donovan

Hi @steve-donovan,

in coming months, we are going to do some changes to mitigate some Code Smells reported by Sonar. One of them is your advice about returning a list or not return nulls.

I will maintain this issue opened.

Good review mate

Juan Antonio

jabrena avatar Aug 16 '22 12:08 jabrena