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 2022/07/14 12:51:24 UTC
[commons-configuration] branch master updated: [CONFIGURATION-799] CombinedConfiguration#getKeys() can throw NoSuchElementException.
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 eb6ee52e [CONFIGURATION-799] CombinedConfiguration#getKeys() can throw NoSuchElementException.
eb6ee52e is described below
commit eb6ee52eb93836f607db0684049e0be68447c3ec
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Thu Jul 14 08:51:18 2022 -0400
[CONFIGURATION-799] CombinedConfiguration#getKeys() can throw
NoSuchElementException.
---
src/changes/changes.xml | 3 +++
.../configuration2/CombinedConfiguration.java | 3 ++-
.../configuration2/TestCombinedConfiguration.java | 20 ++++++++++++++++++++
3 files changed, 25 insertions(+), 1 deletion(-)
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 43368a3d..834fa050 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -26,6 +26,9 @@
<action issue="CONFIGURATION-815" type="fix" dev="ggregory" due-to="Gary Gregory">
Replace optional Apache Log4j 1.2.17 with 2.18.0.
</action>
+ <action issue="CONFIGURATION-799" type="fix" dev="ggregory" due-to="Jarek Sacha, Gary Gregory">
+ CombinedConfiguration#getKeys() can throw NoSuchElementException.
+ </action>
<!-- ADD -->
<!-- UPDATE -->
<action type="update" dev="ggregory" due-to="Dependabot">
diff --git a/src/main/java/org/apache/commons/configuration2/CombinedConfiguration.java b/src/main/java/org/apache/commons/configuration2/CombinedConfiguration.java
index 909680b4..f73e9eee 100644
--- a/src/main/java/org/apache/commons/configuration2/CombinedConfiguration.java
+++ b/src/main/java/org/apache/commons/configuration2/CombinedConfiguration.java
@@ -42,6 +42,7 @@ import org.apache.commons.configuration2.tree.NodeTreeWalker;
import org.apache.commons.configuration2.tree.QueryResult;
import org.apache.commons.configuration2.tree.TreeUtils;
import org.apache.commons.configuration2.tree.UnionCombiner;
+import org.apache.commons.lang3.StringUtils;
/**
* <p>
@@ -928,7 +929,7 @@ public class CombinedConfiguration extends BaseHierarchicalConfiguration impleme
* @return a collection with the names of the single components
*/
private Collection<String> parseAt(final String at) {
- if (at == null) {
+ if (StringUtils.isEmpty(at)) {
return null;
}
diff --git a/src/test/java/org/apache/commons/configuration2/TestCombinedConfiguration.java b/src/test/java/org/apache/commons/configuration2/TestCombinedConfiguration.java
index 032d6478..eff7bcad 100644
--- a/src/test/java/org/apache/commons/configuration2/TestCombinedConfiguration.java
+++ b/src/test/java/org/apache/commons/configuration2/TestCombinedConfiguration.java
@@ -31,6 +31,7 @@ import java.io.StringWriter;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
+import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.concurrent.CountDownLatch;
@@ -760,6 +761,25 @@ public class TestCombinedConfiguration {
checkCombinedRootNotConstructed();
}
+ /**
+ * Tests CONFIGURATION-799.
+ */
+ @Test
+ public void testGetKeys() {
+ // Set up
+ final BaseConfiguration conf1 = new BaseConfiguration();
+ final String key = "x1";
+ conf1.addProperty(key, 1);
+
+ final CombinedConfiguration conf2 = new CombinedConfiguration();
+ conf2.addConfiguration(conf1, null, "");
+
+ // Actual test
+ final Iterator<String> keys = conf2.getKeys();
+ assertEquals(key, keys.next());
+ assertFalse(keys.hasNext());
+ }
+
/**
* Tests whether getNodeCombiner() is correctly synchronized.
*/