You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@zookeeper.apache.org by ar...@apache.org on 2020/01/20 07:41:40 UTC

[zookeeper] branch branch-3.5 updated: ZOOKEEPER-3667: Setting jute.maxbuffer value in hexadecimal throws Exception

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

arshad pushed a commit to branch branch-3.5
in repository https://gitbox.apache.org/repos/asf/zookeeper.git


The following commit(s) were added to refs/heads/branch-3.5 by this push:
     new 4a20176  ZOOKEEPER-3667: Setting jute.maxbuffer value in hexadecimal throws Exception
4a20176 is described below

commit 4a20176e4c48fe32c60272ba4bd6aeac490bc0e7
Author: Sujith Simon <su...@huawei.com>
AuthorDate: Mon Jan 20 13:09:29 2020 +0530

    ZOOKEEPER-3667: Setting jute.maxbuffer value in hexadecimal throws Exception
    
    Author: sujithsimon22 <su...@huawei.com>
    
    Reviewers: Mohammad Arshad <ar...@apache.org>
    
    Closes #1222 from sujithsimon22/3667
    
    (cherry picked from commit 49ad75b18bfe26e853050f5add6f10f567399058)
    Signed-off-by: Mohammad Arshad <ar...@apache.org>
---
 .../java/org/apache/zookeeper/common/ZKConfig.java |  2 +-
 .../zookeeper/client/ZKClientConfigTest.java       | 25 ++++++++++++++++++++++
 2 files changed, 26 insertions(+), 1 deletion(-)

diff --git a/zookeeper-server/src/main/java/org/apache/zookeeper/common/ZKConfig.java b/zookeeper-server/src/main/java/org/apache/zookeeper/common/ZKConfig.java
index 43bc2d8..3d18977 100644
--- a/zookeeper-server/src/main/java/org/apache/zookeeper/common/ZKConfig.java
+++ b/zookeeper-server/src/main/java/org/apache/zookeeper/common/ZKConfig.java
@@ -289,7 +289,7 @@ public class ZKConfig {
     public int getInt(String key, int defaultValue) {
         String value = getProperty(key);
         if (value != null) {
-            return Integer.parseInt(value.trim());
+            return Integer.decode(value.trim());
         }
         return defaultValue;
     }
diff --git a/zookeeper-server/src/test/java/org/apache/zookeeper/client/ZKClientConfigTest.java b/zookeeper-server/src/test/java/org/apache/zookeeper/client/ZKClientConfigTest.java
index 00a57f4..6d3cfbd 100644
--- a/zookeeper-server/src/test/java/org/apache/zookeeper/client/ZKClientConfigTest.java
+++ b/zookeeper-server/src/test/java/org/apache/zookeeper/client/ZKClientConfigTest.java
@@ -188,4 +188,29 @@ public class ZKClientConfigTest {
         assertEquals(value, result);
     }
 
+    @Test
+    public void testIntegerRetrievalFromHexadecimalProperty() {
+        int hexaValue = 0x3000000;
+        String wrongValue = "0xwel";
+        int defaultValue = 100;
+        // property is set in hexadecimal value
+        ZKClientConfig zkClientConfig = new ZKClientConfig();
+        zkClientConfig.setProperty(ZKConfig.JUTE_MAXBUFFER,
+                Integer.toString(hexaValue));
+        int result = zkClientConfig.getInt(ZKConfig.JUTE_MAXBUFFER, defaultValue);
+        assertEquals(result, hexaValue);
+        zkClientConfig.setProperty(ZKConfig.JUTE_MAXBUFFER,
+                wrongValue);
+        try {
+            result = zkClientConfig.getInt(ZKConfig.JUTE_MAXBUFFER, defaultValue);
+            fail("NumberFormatException is expected");
+        } catch (NumberFormatException exception) {
+            // do nothing
+        }
+        zkClientConfig.setProperty(ZKConfig.JUTE_MAXBUFFER,
+                " " + hexaValue + " ");
+        result = zkClientConfig.getInt(ZKConfig.JUTE_MAXBUFFER, defaultValue);
+        assertEquals(result, hexaValue);
+    }
+
 }