Skip to content
Permalink
Browse files
Fix overflow false positive error detected by "strict" compile with
errorProne.
  • Loading branch information
leerho committed Jul 22, 2019
1 parent 966f9bf commit 5a0e03f9a6e4021e6da79ba6e132f5679f9f3364
Showing 2 changed files with 12 additions and 5 deletions.
@@ -83,7 +83,7 @@ public void checkSelfArrayCopy() {
public void checkEquals() {
int len = 7;
WritableMemory wmem1 = WritableMemory.allocate(len);
//@SuppressWarnings({"EqualsWithItself", "SelfEquals"})
@SuppressWarnings({"EqualsWithItself", "SelfEquals"})
//SelfEquals for Plexus, EqualsWithItself for IntelliJ
boolean eq1 = wmem1.equals(wmem1);
assertTrue(eq1);
@@ -126,7 +126,7 @@ public void checkEquals2() {
int len = 23;
WritableMemory wmem1 = WritableMemory.allocate(len);
assertFalse(wmem1.equals(null));
//@SuppressWarnings({"EqualsWithItself", "SelfEquals"})
@SuppressWarnings({"EqualsWithItself", "SelfEquals"})
//SelfEquals for Plexus, EqualsWithItself for IntelliJ
boolean eq1 = wmem1.equals(wmem1);
assertTrue(eq1);
@@ -79,11 +79,12 @@ public void byteArrChecks() {

/*
* This test is modeled from
* <a href="https://github.com/OpenHFT/Zero-Allocation-Hashing/blob/master/src/test/java/net/openhft/hashing/XxHashTest.java">
* <a href="https://github.com/OpenHFT/Zero-Allocation-Hashing/blob/master/src/test/java/net\
* /openhft/hashing/XxHashCollisionTest.java">
* OpenHFT/Zero-Allocation-Hashing</a> to test hash compatibility with that implementation.
* It is licensed under Apache License, version 2.0.
*/
@Test
//@SuppressWarnings("ConstantOverflow")
public void collisionTest() {
WritableMemory wmem = WritableMemory.allocate(128);
wmem.putLong(0, 1);
@@ -97,12 +98,18 @@ public void collisionTest() {
assertEquals(h1, h2);

wmem.putLong(0, 1L + (0xBA79078168D4BAFL * 2));
wmem.putLong(32, 2L + (0x9C90005B80000000L * 2));
wmem.putLong(32, 2L + (0x392000b700000000L)); //= (0x9C90005B80000000L * 2) fix overflow false pos

long h3 = wmem.xxHash64(0, wmem.getCapacity(), 0);
assertEquals(h2, h3);
}

// @Test
// public void fixOverflow() {
// long out = 0x9C90005B80000000L * 2L;
// System.out.println(Long.toHexString(out));
// }

/**
* This simple test compares the output of {@link BaseState#xxHash64(long, long, long)} with the
* output of {@link net.openhft.hashing.LongHashFunction}, that itself is tested against the

0 comments on commit 5a0e03f

Please sign in to comment.