Always false expressions in ConcurrentHashMap source

Tagir Valeev amaembo at
Fri Mar 16 06:18:13 UTC 2018


Experimenting with code static analysis I found several always false
expressions in ConcurrentHashMap source. See addCount method:

if (sc < 0) {
    if ((sc >>> RESIZE_STAMP_SHIFT) != rs || sc == rs + 1 ||
        sc == rs + MAX_RESIZERS || ...


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

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