This is an automated email from the ASF dual-hosted git repository.
jbonofre pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/karaf.git
The following commit(s) were added to refs/heads/main by this push:
new 724920d293 Fix override of numeric value via env variable or system
property (#2251)
724920d293 is described below
commit 724920d29312806741cc71dee6673927b6635eb2
Author: JB Onofré <[email protected]>
AuthorDate: Mon Feb 2 19:13:43 2026 +0100
Fix override of numeric value via env variable or system property (#2251)
---
.../karaf/config/core/impl/KarafConfigurationPlugin.java | 15 ++++++---------
.../config/core/impl/KarafConfigurationPluginTest.java | 5 +++++
2 files changed, 11 insertions(+), 9 deletions(-)
diff --git
a/config/core/src/main/java/org/apache/karaf/config/core/impl/KarafConfigurationPlugin.java
b/config/core/src/main/java/org/apache/karaf/config/core/impl/KarafConfigurationPlugin.java
index 56261ca0e4..27099a0fd3 100644
---
a/config/core/src/main/java/org/apache/karaf/config/core/impl/KarafConfigurationPlugin.java
+++
b/config/core/src/main/java/org/apache/karaf/config/core/impl/KarafConfigurationPlugin.java
@@ -48,10 +48,9 @@ public class KarafConfigurationPlugin implements
ConfigurationPlugin {
properties.put(key, values);
} else {
value = InterpolationHelper.substVars(value, null,null,
convertDictionaryToMap(properties));
- try {
- int intValue = Integer.parseInt(value);
- properties.put(key, intValue);
- } catch (NumberFormatException e) {
+ if (properties.get(key) != null && (properties.get(key)
instanceof Number)) {
+ properties.put(key, Integer.parseInt(value));
+ } else {
properties.put(key, value);
}
}
@@ -66,14 +65,12 @@ public class KarafConfigurationPlugin implements
ConfigurationPlugin {
properties.put(key, values);
} else {
value = InterpolationHelper.substVars(value, null,null,
convertDictionaryToMap(properties));
- try {
- int intValue = Integer.parseInt(value);
- properties.put(key, intValue);
- } catch (NumberFormatException e) {
+ if (properties.get(key) != null && (properties.get(key)
instanceof Number)) {
+ properties.put(key, Integer.parseInt(value));
+ } else {
properties.put(key, value);
}
}
-
}
}
}
diff --git
a/config/core/src/test/java/org/apache/karaf/config/core/impl/KarafConfigurationPluginTest.java
b/config/core/src/test/java/org/apache/karaf/config/core/impl/KarafConfigurationPluginTest.java
index cd2a138b7b..3a0c158a57 100644
---
a/config/core/src/test/java/org/apache/karaf/config/core/impl/KarafConfigurationPluginTest.java
+++
b/config/core/src/test/java/org/apache/karaf/config/core/impl/KarafConfigurationPluginTest.java
@@ -28,14 +28,19 @@ public class KarafConfigurationPluginTest {
@Test
public void testSystemProperty() throws Exception {
System.setProperty("org.apache.karaf.shell.sshPort", "8102");
+ System.setProperty("org.apache.karaf.shell.sshPorts", "[8102,8103]");
KarafConfigurationPlugin plugin = new KarafConfigurationPlugin();
Dictionary<String, Object> properties = new Hashtable<>();
properties.put(Constants.SERVICE_PID, "org.apache.karaf.shell");
properties.put("foo", "bar");
properties.put("sshPort", 8101);
+ properties.put("sshPorts", new String[] { "8102" });
plugin.modifyConfiguration(null, properties);
Assert.assertEquals(8102, properties.get("sshPort"));
+ Assert.assertEquals(2, ((String[])properties.get("sshPorts")).length);
+ Assert.assertEquals("8102", ((String[])properties.get("sshPorts"))[0]);
+ Assert.assertEquals("8103", ((String[])properties.get("sshPorts"))[1]);
Assert.assertEquals("bar", properties.get("foo"));
}