You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2024/06/03 18:35:50 UTC
(commons-configuration) branch master updated: CONFIGURATION-847 property with an empty string value was not processed (#431)
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-configuration.git
The following commit(s) were added to refs/heads/master by this push:
new c2ed6df8 CONFIGURATION-847 property with an empty string value was not processed (#431)
c2ed6df8 is described below
commit c2ed6df8c1576d1ee067f736a178c93f7b4962f9
Author: Andrea Bollini <an...@4science.com>
AuthorDate: Mon Jun 3 20:35:45 2024 +0200
CONFIGURATION-847 property with an empty string value was not processed (#431)
---
.../spring/ConfigurationPropertySource.java | 16 ++++++++------
.../spring/TestConfigurationPropertySource.java | 25 ++++++++++++++++------
2 files changed, 28 insertions(+), 13 deletions(-)
diff --git a/src/main/java/org/apache/commons/configuration2/spring/ConfigurationPropertySource.java b/src/main/java/org/apache/commons/configuration2/spring/ConfigurationPropertySource.java
index 6f544584..8035b1f0 100644
--- a/src/main/java/org/apache/commons/configuration2/spring/ConfigurationPropertySource.java
+++ b/src/main/java/org/apache/commons/configuration2/spring/ConfigurationPropertySource.java
@@ -39,14 +39,18 @@ public class ConfigurationPropertySource extends EnumerablePropertySource<Config
@Override
public Object getProperty(final String name) {
- final String[] propValue = source.getStringArray(name);
- if (propValue == null || propValue.length == 0) {
+ if (source.getProperty(name) != null) {
+ final String[] propValue = source.getStringArray(name);
+ if (propValue == null || propValue.length == 0) {
+ return "";
+ } else if (propValue.length == 1) {
+ return propValue[0];
+ } else {
+ return propValue;
+ }
+ } else {
return null;
}
- if (propValue.length == 1) {
- return propValue[0];
- }
- return propValue;
}
@Override
diff --git a/src/test/java/org/apache/commons/configuration2/spring/TestConfigurationPropertySource.java b/src/test/java/org/apache/commons/configuration2/spring/TestConfigurationPropertySource.java
index daffd03f..1d5bf157 100644
--- a/src/test/java/org/apache/commons/configuration2/spring/TestConfigurationPropertySource.java
+++ b/src/test/java/org/apache/commons/configuration2/spring/TestConfigurationPropertySource.java
@@ -20,6 +20,7 @@ package org.apache.commons.configuration2.spring;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import org.apache.commons.configuration2.PropertiesConfiguration;
import org.junit.jupiter.api.AfterAll;
@@ -67,6 +68,8 @@ public class TestConfigurationPropertySource {
private static final String TEST_NULL_PROPERTY = "test.null.property";
+ private static final String TEST_EMPTY_PROPERTY = "test.empty.property";
+
private static final String TEST_VALUE = "testVALUE";
private static final String TEST_SYSTEM_VALUE = "testVALUEforSystemEnv";
@@ -83,6 +86,7 @@ public class TestConfigurationPropertySource {
propertiesConfiguration.addProperty(TEST_LIST_PROPERTY, TEST_LIST_PROPERTY_VALUE);
propertiesConfiguration.addProperty(TEST_SYSTEM_PROPERTY, TEST_SYSTEM_PROPERTY_VALUE);
propertiesConfiguration.addProperty(TEST_NULL_PROPERTY, null);
+ propertiesConfiguration.addProperty(TEST_EMPTY_PROPERTY, "");
return new ConfigurationPropertySource("test configuration", propertiesConfiguration);
}
@@ -106,7 +110,13 @@ public class TestConfigurationPropertySource {
private String systemPropertyValue;
@Value("${" + TEST_NULL_PROPERTY + ":false}")
- private boolean booleanNullValue;
+ private boolean booleanNullValueDefaultFalse;
+
+ @Value("${" + TEST_NULL_PROPERTY + ":true}")
+ private boolean booleanNullValueDefaultTrue;
+
+ @Value("${" + TEST_EMPTY_PROPERTY + ":defaultShouldNotApply}")
+ private String emptyPropertyValue;
@Test
public void testListValueInjection() {
@@ -114,17 +124,18 @@ public class TestConfigurationPropertySource {
}
@Test
- public void testNullValueInjection() {
- assertFalse(booleanNullValue);
+ public void testSystemPropertyValueInjection() {
+ assertEquals(TEST_SYSTEM_VALUE, systemPropertyValue);
}
@Test
- public void testSystemPropertyValueInjection() {
- assertEquals(TEST_SYSTEM_VALUE, systemPropertyValue);
+ public void testNullValueInjection() {
+ assertFalse(booleanNullValueDefaultFalse);
+ assertTrue(booleanNullValueDefaultTrue);
}
@Test
- public void testValueInjection() {
- assertEquals(TEST_VALUE, value);
+ public void testEmptyStringValueInjection() {
+ assertEquals("", emptyPropertyValue);
}
}