-
Enhancement
-
Resolution: Fixed
-
P4
-
None
-
b17
There is a providerIndex field that means "the next provider we need to query" and it's never reset, which means the list can only be iterated once. Some of its methods like size() and get() cannot be called, otherwise it updates providerIndex and iterating it will either skip some items or fail.
While JDK iterates each ServiceList only once and never call the other methods, there is a risk that someone will forget this rule. Also, when running in a debugger, the debugger might call size() automatically to show the content of this object and it could make the object not useable.
Since it's always only iterated once, we can rewrite it as an Iterator.
While JDK iterates each ServiceList only once and never call the other methods, there is a risk that someone will forget this rule. Also, when running in a debugger, the debugger might call size() automatically to show the content of this object and it could make the object not useable.
Since it's always only iterated once, we can rewrite it as an Iterator.