magefree / magefree/mage

Refactor: wrong usage of iterator().next()

Open
#11,015 2 comments 0 reactions 0 assignees View on GitHub
bug refactoring
Dominant language
Java
Stars
2.4k
Forks
940
Avg merge
2d 12h
Merged PRs (30d)
160

Description

There are many usages of `iterator().next()` -- but it can raise `NoSuchElementException` error on empty list, so all related code must check it before call `next()`.

Search code for: `iterator().next()`

There are ~150 places to check.

Good code example:
![shot_230825_185904](https://github.com/magefree/mage/assets/8344157/79ab1867-9140-4fe6-80e9-ef74f7b118b0)

Bad code and fixes example:
640e5394c9d433ea07de57f4b22fee9dadd7dcb5, 0db46ba3dacf34945fa9ba27fbfbe0c9cfd43a37

Contributor guide

No contributing guide indexed for this repository

Research direction

Search the codebase for every `iterator().next()` usage, then compare each case with the good and bad examples in the issue and the referenced commits. Review whether the collection can be empty and ensure all roughly 150 occurrences handle that case safely; done means the search finds no unreviewed usages.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
backend
Issue type
Refactor
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.