sonny8441 / google-collections

Automatically exported from code.google.com/p/google-collections
Apache License 2.0
0 stars 0 forks source link

Iterators.forArray(Object[], int, int) third parameter is WRONG! #270

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
All the public methods of java.util.Arrays interpret "int, int" as being a 
start index (inclusive) and end index (exclusive).  List.subList() and many 
other APIs work this way.  A minority of APIs, which seem mostly confined 
to java.io, use instead start index (inclusive) and *length*.

I think our Iterators.forArray(Object[], int, int) method totally chose the 
wrong model to follow, and this is inevitably going to cause bugs.

On the bright side, I doubt many users are using it.  We can either:

- Just change it, and try to warn as loudly as we can for users to 
carefully check their code before upgrading

- Just remove it for 1.0, since it's not really that important anyway. We 
still have the option to add it back later, where it could only cause 
trouble if someone upgraded straight from <=1.0-rc3 to this future version, 
skipping over 1.0-final.

Original issue reported on code.google.com by kevin...@gmail.com on 23 Oct 2009 at 7:08

GoogleCodeExporter commented 9 years ago
another option: just rename it to something else, like forArrayRange or 
forArrayIndex
people currently using it will get an compile error and will have to check the
documentation how to adapt their code.

Original comment by heroldsi...@googlemail.com on 27 Oct 2009 at 1:06

GoogleCodeExporter commented 9 years ago
You're right, that is an option... just one that leaves an undesirable end 
state of 
the method having a weird name.  (Iterators.forSubarray()?)

Either we do that, or I'm leaning toward just removing it.  Users do have the 
workaround of Arrays.asList().subList().iterator().....

Original comment by kevin...@gmail.com on 29 Oct 2009 at 7:02

GoogleCodeExporter commented 9 years ago
Definitely going to remove it.  I discovered that the vast majority of our 
internal 
users are using it like "Iterators.forArray(a, 0, a.length)"... thus deriving 
negative 
value from the presence of this overload.

Original comment by kevin...@gmail.com on 3 Nov 2009 at 6:32

GoogleCodeExporter commented 9 years ago

Original comment by kevin...@gmail.com on 5 Nov 2009 at 1:11