amadeus4dev / amadeus-java

Java library for the Amadeus Self-Service travel APIs
https://developers.amadeus.com/
MIT License
87 stars 69 forks source link

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

Open steve-donovan opened 2 years ago

steve-donovan commented 2 years ago

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 commented 2 years ago

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

jabrena commented 2 years ago

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