This is an automated email from the ASF dual-hosted git repository. jbonofre pushed a commit to branch karaf-4.2.x in repository https://gitbox.apache.org/repos/asf/karaf.git
The following commit(s) were added to refs/heads/karaf-4.2.x by this push: new d157694a33 KARAF-7522 Fix stack overflow error with duplicate features. new e2357b3ab4 Merge pull request #1604 from splatch/KARAF-7522 d157694a33 is described below commit d157694a33dd15f4fb31ddf8079e2849451990a1 Author: Łukasz Dywicki <l...@code-house.org> AuthorDate: Fri Jul 22 16:44:10 2022 +0200 KARAF-7522 Fix stack overflow error with duplicate features. Signed-off-by: Łukasz Dywicki <l...@code-house.org> --- .../karaf/features/internal/region/Subsystem.java | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/features/core/src/main/java/org/apache/karaf/features/internal/region/Subsystem.java b/features/core/src/main/java/org/apache/karaf/features/internal/region/Subsystem.java index c9b374074b..e68929e05d 100644 --- a/features/core/src/main/java/org/apache/karaf/features/internal/region/Subsystem.java +++ b/features/core/src/main/java/org/apache/karaf/features/internal/region/Subsystem.java @@ -23,6 +23,7 @@ import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; +import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Set; @@ -329,7 +330,23 @@ public class Subsystem extends ResourceImpl { @SuppressWarnings("InfiniteLoopStatement") public void build(Map<String, List<Feature>> allFeatures) throws Exception { - doBuild(allFeatures, true); + Map<String, List<Feature>> cleaned = new LinkedHashMap<>(); + for (Map.Entry<String, List<Feature>> entry : allFeatures.entrySet()) { + if (entry.getValue().size() > 1) { + Map<String, Feature> versionMap = new LinkedHashMap<>(); + for (Feature feature : entry.getValue()) { + if (!versionMap.containsKey(feature.getVersion())) { + versionMap.put(feature.getVersion(), feature); + } else { + // warn about duplicate + } + } + cleaned.put(entry.getKey(), new ArrayList<>(versionMap.values())); + } else { + cleaned.put(entry.getKey(), entry.getValue()); + } + } + doBuild(cleaned, true); } private void doBuild(Map<String, List<Feature>> allFeatures, boolean mandatory) throws Exception {