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

TurfMeasurement#length method cannot handle empty lists

Open Blafasel3 opened this issue 3 years ago • 0 comments

The other day, I encountered what I regard as an issue in the following Code snippet: https://github.com/mapbox/mapbox-java/blob/4ae8b78746fb37b2673364bdd4c8702057f3e7f3/services-turf/src/main/java/com/mapbox/turf/TurfMeasurement.java#L227 The scenario is the following: We have a list of GPS points of which some or all are invalid which is denoted by the coordinates being (0 , 0) - which IS bad Design, but our Team cannot change this... 🙄. Thus, we filter out those points before passing it to the length method. We just encountered an IndexOutOfBoundsException when the list is empty because there is no length check on the list. I guess the fix here is relatively easy, but the question ist - what should be returned in this case. We built in a check before hand returning 0 in this particular case. Maybe even a checked exception might be a feasible idea.

Blafasel3 avatar Aug 26 '22 19:08 Blafasel3