Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
steve-donovan opened this issue Aug 10, 2022 · 2 comments
Labels
enhancement New feature or request

Comments

@steve-donovan
Copy link
Contributor

steve-donovan commented Aug 10, 2022

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
Copy link
Contributor Author

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

@jabrena
Copy link
Contributor

jabrena commented Aug 16, 2022

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

@tsolakoua tsolakoua added the enhancement New feature or request label Apr 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants