You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by cl...@apache.org on 2020/05/19 22:34:23 UTC

[activemq-artemis] branch master updated: ARTEMIS-2769 ConfigurationHelper Test returning default on parsing error

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

clebertsuconic pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/activemq-artemis.git


The following commit(s) were added to refs/heads/master by this push:
     new 001a4b4  ARTEMIS-2769 ConfigurationHelper Test returning default on parsing error
     new 818ab3d  This closes #3141
001a4b4 is described below

commit 001a4b409e2e83e2ae2b367ec4cb62b16ecaf586
Author: Clebert Suconic <cl...@apache.org>
AuthorDate: Tue May 19 15:49:26 2020 -0400

    ARTEMIS-2769 ConfigurationHelper Test returning default on parsing error
---
 .../artemis/utils/ConfigurationHelper.java         | 15 ++++++--
 .../artemis/util/ConfigurationHelperTest.java      | 42 ++++++++++++++++++++++
 2 files changed, 55 insertions(+), 2 deletions(-)

diff --git a/artemis-core-client/src/main/java/org/apache/activemq/artemis/utils/ConfigurationHelper.java b/artemis-core-client/src/main/java/org/apache/activemq/artemis/utils/ConfigurationHelper.java
index 3b2647c..e765df4 100644
--- a/artemis-core-client/src/main/java/org/apache/activemq/artemis/utils/ConfigurationHelper.java
+++ b/artemis-core-client/src/main/java/org/apache/activemq/artemis/utils/ConfigurationHelper.java
@@ -54,7 +54,13 @@ public class ConfigurationHelper {
       } else {
          // The resource adapter will aways send Strings, hence the conversion here
          if (prop instanceof String) {
-            return Integer.valueOf((String) prop);
+            try {
+               return Integer.valueOf((String) prop);
+            } catch (NumberFormatException e) {
+               ActiveMQClientLogger.LOGGER.propertyNotInteger(propName, prop.getClass().getName());
+
+               return def;
+            }
          } else if (prop instanceof Number == false) {
             ActiveMQClientLogger.LOGGER.propertyNotInteger(propName, prop.getClass().getName());
 
@@ -77,7 +83,12 @@ public class ConfigurationHelper {
       } else {
          // The resource adapter will aways send Strings, hence the conversion here
          if (prop instanceof String) {
-            return Long.valueOf((String) prop);
+            try {
+               return Long.valueOf((String) prop);
+            } catch (NumberFormatException e) {
+               ActiveMQClientLogger.LOGGER.propertyNotLong(propName, prop.getClass().getName());
+               return def;
+            }
          } else if (prop instanceof Number == false) {
             ActiveMQClientLogger.LOGGER.propertyNotLong(propName, prop.getClass().getName());
 
diff --git a/artemis-core-client/src/test/java/org/apache/activemq/artemis/util/ConfigurationHelperTest.java b/artemis-core-client/src/test/java/org/apache/activemq/artemis/util/ConfigurationHelperTest.java
new file mode 100644
index 0000000..db87e68
--- /dev/null
+++ b/artemis-core-client/src/test/java/org/apache/activemq/artemis/util/ConfigurationHelperTest.java
@@ -0,0 +1,42 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.activemq.artemis.util;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.activemq.artemis.utils.ConfigurationHelper;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class ConfigurationHelperTest {
+
+   @Test
+   public void testDefaultInt() {
+      Map<String, Object> values = new HashMap<>();
+      values.put("test", "zzz");
+      Assert.assertEquals(3, ConfigurationHelper.getIntProperty("test", 3, values));
+   }
+
+   @Test
+   public void testDefaultLong() {
+      Map<String, Object> values = new HashMap<>();
+      values.put("test", "zzz");
+      Assert.assertEquals(3L, ConfigurationHelper.getLongProperty("test", 3L, values));
+   }
+}