CORDA-2772 - fix edge case when stickTo.hashCode return Int.MIN_VALUE

This commit is contained in:
dazraf 2019-03-21 16:05:53 +00:00 committed by Mike Hearn
parent c33ccc1e1b
commit b6f9b86998

View File

@ -25,7 +25,12 @@ class LazyStickyPool<A : Any>(
private val boxes = Array(size) { InstanceBox<A>() }
private fun toIndex(stickTo: Any): Int {
return Math.abs(stickTo.hashCode()) % boxes.size
return stickTo.hashCode().let { hashCode ->
when (hashCode) {
Int.MIN_VALUE -> 0
else -> Math.abs(hashCode) % boxes.size
}
}
}
fun borrow(stickTo: Any): A {