Always false expressions in ConcurrentHashMap source
Tagir Valeev
amaembo at gmail.com
Fri Mar 16 06:18:13 UTC 2018
Hello!
Experimenting with code static analysis I found several always false
expressions in ConcurrentHashMap source. See addCount method:
http://hg.openjdk.java.net/jdk/jdk/file/422615764e12/src/java.base/share/classes/java/util/concurrent/ConcurrentHashMap.java#l2352
if (sc < 0) {
if ((sc >>> RESIZE_STAMP_SHIFT) != rs || sc == rs + 1 ||
sc == rs + MAX_RESIZERS || ...
RESIZE_STAMP_SHIFT is 16, MAX_RESIZERS is 65535
While sc is a negative inside if, "(sc >>> RESIZE_STAMP_SHIFT)" is a
positive number (more precisely, in {32768..65535} range). So if the "(sc
>>> RESIZE_STAMP_SHIFT) != rs" is false, then
rs is equal to "(sc >>> RESIZE_STAMP_SHIFT)", thus it's also in the same
range. This makes the condition "sc == rs + 1" always false when reached
(rs+1 is {32769..65536}, but sc is negative here). Also "sc == rs +
MAX_RESIZERS" is always false when reached (rs+MAX_RESIZERS is
{98303..131070}).
Similar code also appears in helpTransfer method below (line 2378) and also
contains two always false conditions.
I don't know whether something else was meant here, or these checks are
redundant. Just wanted to draw your attention.
With best regards,
Tagir Valeev.
More information about the core-libs-dev
mailing list