When invalid sizes are used to initialize the ArrayList

When numberOfPairs is invalid (too big to be correct), don't crash with an OOM error.
Additional to #289