Looking up a value which has its 32 least significant bits set to
zero will lead to Uint64.ZERO being returned. This also affects other
values which have LSB bits set so that they match cache length.
Fix this by comparing the long value with cache length, so we get
an accurate check.
JIRA: YANGTOOLS-1028
Change-Id: I33bf061e5ff486beaf034cab7827f93e93003489
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
}
private static Uint64 instanceFor(final long value) {
- final int slot = (int)value;
- return slot >= 0 && slot < CACHE.length ? CACHE[slot] : new Uint64(value);
+ return value >= 0 && value < CACHE.length ? CACHE[(int) value] : new Uint64(value);
}
/**
assertEquals(2147483647, Uint64.valueOf(Integer.MAX_VALUE).intValue());
assertEquals(9223372036854775807L, Uint64.valueOf(Long.MAX_VALUE).longValue());
assertEquals(0, Uint64.valueOf("0").intValue());
+ assertEquals(2170205184637009920L, Uint64.valueOf(2170205184637009920L).longValue());
+ assertEquals(2170205184637009920L, Uint64.valueOf(new BigInteger("2170205184637009920")).longValue());
}
@Test