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 c89249a9f0 KARAF-7522 Fix stack overflow error with duplicate features. c89249a9f0 is described below commit c89249a9f0b3049d941127a45eaadbd6220e8454 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> (cherry picked from commit d157694a33dd15f4fb31ddf8079e2849451990a1) --- .../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 4ab53a8e04..2dbd875dfc 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 {