dungba88 commented on code in PR #12844: URL: https://github.com/apache/lucene/pull/12844#discussion_r1423317624
########## lucene/core/src/java/org/apache/lucene/util/ArrayUtil.java: ########## @@ -330,15 +330,36 @@ public static int[] growExact(int[] array, int newLength) { return copy; } + /** + * Returns an array whose size is at least {@code minLength}, generally over-allocating + * exponentially, but never allocating more than {@code maxLength} elements. + */ + public static int[] growInRange(int[] array, int minLength, int maxLength) { + assert minLength >= 0 + : "length must be positive (got " + minLength + "): likely integer overflow?"; + + if (minLength > maxLength) { Review Comment: That's interesting, I didn't realize that. I just learnt recently from #12624 that `assert` was used for the internal code path to catch bug, while throwing exceptions was used for the code path that users can directly control. In Lucene we always have assertion enabled, so `assert` would surely throw in tests. This class is marked as internal and not to be used by users so I thought it would be fine to just use `assert` here. Anyhow, I'm fine with either. Maybe other people could have more thoughts here. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org For additional commands, e-mail: issues-h...@lucene.apache.org