Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Null Pointer check in "Range" hash functions #350

Merged
merged 3 commits into from
Jun 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/src/main/java/zingg/hash/RangeDbl.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public RangeDbl(int lower, int upper) {
@Override
public Integer call(Double field) {
int withinRange = 0;
if (field >= lowerLimit && field < upperLimit) {
if (field != null && field >= lowerLimit && field < upperLimit) {
withinRange = 1;
}
return withinRange;
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/zingg/hash/RangeInt.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public RangeInt(int lower, int upper) {
@Override
public Integer call(Integer field) {
int withinRange = 0;
if (field >= lowerLimit && field < upperLimit) {
if (field != null && field >= lowerLimit && field < upperLimit) {
withinRange = 1;
}
return withinRange;
Expand Down
4 changes: 2 additions & 2 deletions core/src/test/java/zingg/hash/TestLessThanZeroInt.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ public void testLessThanZeroIntForValueZero() {
}

@Test
public void testLessThanZeroDblForValueNull() {
LessThanZeroDbl value = new LessThanZeroDbl();
public void testLessThanZeroIntForValueNull() {
LessThanZeroInt value = new LessThanZeroInt();
assertFalse(value.call(null));
}

Expand Down
6 changes: 5 additions & 1 deletion core/src/test/java/zingg/hash/TestRangeBetween0And10Dbl.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,9 @@ public void testRangeForValue8637() {
RangeDbl value = new RangeBetween0And10Dbl();
assertEquals(0, value.call(8637d));
}

@Test
public void testRangeForNull() {
RangeDbl value = new RangeBetween0And10Dbl();
assertEquals(0, value.call(null));
}
}
5 changes: 5 additions & 0 deletions core/src/test/java/zingg/hash/TestRangeBetween0And10Int.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,10 @@ public void testRangeForValue8637() {
RangeInt value = new RangeBetween0And10Int();
assertEquals(0, value.call(8637));
}
@Test
public void testRangeForNull() {
RangeInt value = new RangeBetween0And10Int();
assertEquals(0, value.call(null));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,10 @@ public void testRangeLessThan10000() {
RangeDbl value = new RangeBetween1000And10000Dbl();
assertEquals(1, value.call(8637d));
}
@Test
public void testRangeForNull() {
RangeDbl value = new RangeBetween1000And10000Dbl();
assertEquals(0, value.call(null));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,10 @@ public void testRangeForValue8637() {
RangeInt value = new RangeBetween1000And10000Int();
assertEquals(1, value.call(8637));
}
@Test
public void testRangeForNull() {
RangeInt value = new RangeBetween1000And10000Int();
assertEquals(0, value.call(null));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,10 @@ public void testRangeForValue8637() {
RangeDbl value = new RangeBetween100And1000Dbl();
assertEquals(0, value.call(8637d));
}
@Test
public void testRangeForNull() {
RangeDbl value = new RangeBetween100And1000Dbl();
assertEquals(0, value.call(null));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,10 @@ public void testRangeForValue8637() {
RangeInt value = new RangeBetween100And1000Int();
assertEquals(0, value.call(8637));
}
@Test
public void testRangeForNull() {
RangeInt value = new RangeBetween100And1000Int();
assertEquals(0, value.call(null));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,10 @@ public void testRangeForValue8637() {
RangeDbl value = new RangeBetween10And100Dbl();
assertEquals(0, value.call(8637d));
}
@Test
public void testRangeForNull() {
RangeDbl value = new RangeBetween10And100Dbl();
assertEquals(0, value.call(null));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,10 @@ public void testRangeForValue8637() {
RangeInt value = new RangeBetween10And100Int();
assertEquals(0, value.call(8637));
}
@Test
public void testRangeForNull() {
RangeInt value = new RangeBetween10And100Int();
assertEquals(0, value.call(null));
}

}