TurfMeasurement#length method cannot handle empty lists
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 438
- Forks
- 117
- PR merge metrics
- No merged PRs in 30d
Description
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at services-turf/src/main/java/com/mapbox/turf/TurfMeasurement.java around the linked length method and reproduce the empty-list failure. Check how the method handles normal point lists and review nearby usage to establish the intended empty-input contract. Done means the behavior is agreed, the empty-list case no longer throws unexpectedly, and regression coverage verifies it.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- backend-api-design
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100