diff --git a/implementation/src/main/java/io/smallrye/config/SmallRyeConfigBuilder.java b/implementation/src/main/java/io/smallrye/config/SmallRyeConfigBuilder.java index e4f30ad65..f06d52a5c 100644 --- a/implementation/src/main/java/io/smallrye/config/SmallRyeConfigBuilder.java +++ b/implementation/src/main/java/io/smallrye/config/SmallRyeConfigBuilder.java @@ -34,6 +34,7 @@ import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; +import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.OptionalInt; @@ -213,10 +214,10 @@ public OptionalInt getPriority() { } private List getProfile(final ConfigSourceInterceptorContext context) { - List profiles = new ArrayList<>(); + Set profiles = new LinkedHashSet<>(); profiles.addAll(getProfiles(context, SMALLRYE_CONFIG_PROFILE_PARENT)); profiles.addAll(getProfiles(context, SMALLRYE_CONFIG_PROFILE)); - return profiles; + return new ArrayList<>(profiles); } private List getProfiles(final ConfigSourceInterceptorContext context, final String propertyName) { diff --git a/implementation/src/test/java/io/smallrye/config/ProfileConfigSourceInterceptorTest.java b/implementation/src/test/java/io/smallrye/config/ProfileConfigSourceInterceptorTest.java index ee2a84b3e..6adf136f4 100644 --- a/implementation/src/test/java/io/smallrye/config/ProfileConfigSourceInterceptorTest.java +++ b/implementation/src/test/java/io/smallrye/config/ProfileConfigSourceInterceptorTest.java @@ -10,6 +10,7 @@ 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.assertIterableEquals; import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -502,6 +503,18 @@ void multipleProfileProperty() { assertEquals("double", common.getRawValue("triple.prop")); } + @Test + void duplicatedProfilesActive() { + SmallRyeConfig config = new SmallRyeConfigBuilder() + .addDefaultInterceptors() + .withSources(config(SMALLRYE_CONFIG_PROFILE, "prod,kubernetes")) + .withSources(config(SMALLRYE_CONFIG_PROFILE_PARENT, "cluster")) + .withSources(config("%kubernetes." + SMALLRYE_CONFIG_PROFILE_PARENT, "cluster")) + .build(); + + assertIterableEquals(List.of("kubernetes", "prod", "cluster"), config.getProfiles()); + } + private static SmallRyeConfig buildConfig(String... keyValues) { return new SmallRyeConfigBuilder() .addDefaultInterceptors()