Bug in TIntHashSet.toArray(int[])

Issue #34 resolved
Scott Banachowski created an issue

According to the TIntSet documentation "f the native array is smaller than the set size, the array will be filled with elements in Iterator order until it is full and exclude the remainder."

Looking at the implementation of TIntHashSet, there's no check for the size of the input array, and so supplying a smaller array causes an ArrayIndexOutOfBoundsException.

Either the documentation should be changed to reflect the behavior, or the code should change to fix the bug.

Here's how to reproduce: TIntHashSet hashSet = new TIntHashSet(); hashSet.add(1); hashSet.add(2); hashSet.add(3); int[] ary = hashSet .toArray(new int[2]);

Comments (1)

  1. Log in to comment