zookeeper-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ars...@apache.org
Subject [zookeeper] branch branch-3.6 updated: ZOOKEEPER-3667: Setting jute.maxbuffer value in hexadecimal throws Exception
Date Mon, 20 Jan 2020 07:40:39 GMT
This is an automated email from the ASF dual-hosted git repository.

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


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

commit 261f8b8b913fdf3fb42d0a0fc5763b51abd3f830
Author: Sujith Simon <sujith.abraham.simon@huawei.com>
AuthorDate: Mon Jan 20 13:09:29 2020 +0530

    ZOOKEEPER-3667: Setting jute.maxbuffer value in hexadecimal throws Exception
    
    Author: sujithsimon22 <sujith.abraham.simon@huawei.com>
    
    Reviewers: Mohammad Arshad <arshad@apache.org>
    
    Closes #1222 from sujithsimon22/3667
    
    (cherry picked from commit 49ad75b18bfe26e853050f5add6f10f567399058)
    Signed-off-by: Mohammad Arshad <arshad@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 d7bed70..11cdc06 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
@@ -273,7 +273,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 e0c25a1..9a9b622 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
@@ -185,4 +185,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);
+    }
+
 }


Mime
View raw message