8280459: Suspicious integer division in Hashtable.readHashtable

Reviewed-by: rriggs, bpb
This commit is contained in:
Aleksey Shipilev 2022-01-24 09:18:20 +00:00
parent 9bf6ffa19f
commit d1569111d7

View file

@ -1290,7 +1290,7 @@ public class Hashtable<K,V>
// no larger than the clamped original length. Make the length // no larger than the clamped original length. Make the length
// odd if it's large enough, this helps distribute the entries. // odd if it's large enough, this helps distribute the entries.
// Guard against the length ending up zero, that's not valid. // Guard against the length ending up zero, that's not valid.
int length = (int)((elements + elements / 20) / lf) + 3; int length = (int)(elements * 1.05f / lf) + 3;
if (length > elements && (length & 1) == 0) if (length > elements && (length & 1) == 0)
length--; length--;
length = Math.min(length, origlength); length = Math.min(length, origlength);