You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kylin.apache.org by sh...@apache.org on 2018/11/12 00:59:26 UTC

[kylin] branch master updated: KYLIN-3597, fix the critical bug reported by sonar: Make sure this expression can't be zero before doing this division.

This is an automated email from the ASF dual-hosted git repository.

shaofengshi pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/kylin.git


The following commit(s) were added to refs/heads/master by this push:
     new f0b26c4  KYLIN-3597, fix the critical bug reported by sonar: Make sure this expression can't be zero before doing this division.
f0b26c4 is described below

commit f0b26c42bad84d6ee2cb367557d256e057d9287c
Author: Jiatao Tao <24...@qq.com>
AuthorDate: Sat Nov 3 10:56:07 2018 +0800

    KYLIN-3597, fix the critical bug reported by sonar: Make sure this expression can't be zero before doing this division.
---
 cache/src/main/java/net/spy/memcached/RefinedKetamaNodeLocator.java | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/cache/src/main/java/net/spy/memcached/RefinedKetamaNodeLocator.java b/cache/src/main/java/net/spy/memcached/RefinedKetamaNodeLocator.java
index 95298d7..43f31bc 100644
--- a/cache/src/main/java/net/spy/memcached/RefinedKetamaNodeLocator.java
+++ b/cache/src/main/java/net/spy/memcached/RefinedKetamaNodeLocator.java
@@ -110,7 +110,7 @@ public final class RefinedKetamaNodeLocator extends SpyObject implements NodeLoc
      *          continuum
      * @param alg The hash algorithm to use when choosing a node in the Ketama
      *          consistent hash continuum
-     * @param weights node weights for ketama, a map from InetSocketAddress to
+     * @param nodeWeights node weights for ketama, a map from InetSocketAddress to
      *          weight as Integer
      * @param configuration node locator configuration
      */
@@ -233,7 +233,7 @@ public final class RefinedKetamaNodeLocator extends SpyObject implements NodeLoc
             if (isWeightedKetama) {
 
                 int thisWeight = weights.get(node.getSocketAddress());
-                float percent = (float) thisWeight / (float) totalWeight;
+                float percent = (totalWeight == 0 ? 0f : (float) thisWeight / (float) totalWeight);
                 int pointerPerServer = (int) ((Math.floor(
                         (float) (percent * (float) config.getNodeRepetitions() / 4 * (float) nodeCount + 0.0000000001)))
                         * 4);