Skip to content

Commit

Permalink
NPE occurs when execute show table status (#32776)
Browse files Browse the repository at this point in the history
* Add an early return when the object is null

* Return result is null

* Code Style

* optimize code

* optimize code

* optimize code

* fix
  • Loading branch information
comecny authored Sep 4, 2024
1 parent f14177b commit 1a41252
Showing 1 changed file with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,24 @@ private void merge(final MemoryQueryResultRow row, final MemoryQueryResultRow ne
}

private BigInteger sum(final Object num1, final Object num2) {
return ((BigInteger) num1).add((BigInteger) num2);
if (num1 == null && num2 == null) {
return null;
}
return getNonNullBigInteger(num1).add(getNonNullBigInteger(num2));
}

private BigInteger avg(final Object sum, final Object number) {
return BigInteger.ZERO.equals(number) ? BigInteger.ZERO : ((BigInteger) sum).divide((BigInteger) number);
if (sum == null && number == null) {
return null;
}
BigInteger numberBigInteger = getNonNullBigInteger(number);
return BigInteger.ZERO.equals(numberBigInteger) ? BigInteger.ZERO : getNonNullBigInteger(sum).divide(numberBigInteger);
}

private BigInteger getNonNullBigInteger(final Object value) {
return Optional.ofNullable(value)
.filter(BigInteger.class::isInstance)
.map(BigInteger.class::cast)
.orElse(BigInteger.ZERO);
}
}

0 comments on commit 1a41252

Please sign in to comment.