From d86373137d61c136e95be7d26fc98aa2a76a27d7 Mon Sep 17 00:00:00 2001 From: Roberto Cortez Date: Fri, 19 Apr 2024 20:32:52 +0100 Subject: [PATCH] Consistent collection type for profiles (#1149) --- .../io/smallrye/config/ConfigMappingProvider.java | 2 +- .../config/ProfileConfigSourceInterceptor.java | 10 +++++----- .../main/java/io/smallrye/config/SmallRyeConfig.java | 11 +++++------ 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/implementation/src/main/java/io/smallrye/config/ConfigMappingProvider.java b/implementation/src/main/java/io/smallrye/config/ConfigMappingProvider.java index e2b76d964..ecaa7fb5e 100644 --- a/implementation/src/main/java/io/smallrye/config/ConfigMappingProvider.java +++ b/implementation/src/main/java/io/smallrye/config/ConfigMappingProvider.java @@ -82,7 +82,7 @@ private void matchPropertiesWithEnv(final SmallRyeConfig config) { // TODO - We shouldn't be mutating the EnvSource. // We should do the calculation when creating the EnvSource, but right now mappings and sources are not well integrated. - String[] profiles = config.getProfiles().toArray(new String[0]); + List profiles = config.getProfiles(); boolean all = roots.containsKey(""); StringBuilder sb = new StringBuilder(); diff --git a/implementation/src/main/java/io/smallrye/config/ProfileConfigSourceInterceptor.java b/implementation/src/main/java/io/smallrye/config/ProfileConfigSourceInterceptor.java index cc2f04e07..f8d20c23e 100644 --- a/implementation/src/main/java/io/smallrye/config/ProfileConfigSourceInterceptor.java +++ b/implementation/src/main/java/io/smallrye/config/ProfileConfigSourceInterceptor.java @@ -17,7 +17,7 @@ @Priority(Priorities.LIBRARY + 200) public class ProfileConfigSourceInterceptor implements ConfigSourceInterceptor { private static final long serialVersionUID = -6305289277993917313L; - private final String[] profiles; + private final List profiles; public ProfileConfigSourceInterceptor(final String profile) { this(profile != null ? convertProfile(profile) : new ArrayList<>()); @@ -26,12 +26,12 @@ public ProfileConfigSourceInterceptor(final String profile) { public ProfileConfigSourceInterceptor(final List profiles) { List reverseProfiles = new ArrayList<>(profiles); Collections.reverse(reverseProfiles); - this.profiles = reverseProfiles.toArray(new String[0]); + this.profiles = reverseProfiles; } @Override public ConfigValue getValue(final ConfigSourceInterceptorContext context, final String name) { - if (profiles.length > 0) { + if (profiles.size() > 0) { final String normalizeName = activeName(name, profiles); final ConfigValue profileValue = getProfileValue(context, normalizeName); if (profileValue != null) { @@ -67,11 +67,11 @@ public Iterator iterateNames(final ConfigSourceInterceptorContext contex return names.iterator(); } - public String[] getProfiles() { + public List getProfiles() { return profiles; } - public static String activeName(final String name, final String[] profiles) { + public static String activeName(final String name, final List profiles) { if (!name.isEmpty() && name.charAt(0) == '%') { int profilesEnd = name.indexOf('.', 1); int multipleSplit = -1; diff --git a/implementation/src/main/java/io/smallrye/config/SmallRyeConfig.java b/implementation/src/main/java/io/smallrye/config/SmallRyeConfig.java index e743e8601..a71e01d31 100644 --- a/implementation/src/main/java/io/smallrye/config/SmallRyeConfig.java +++ b/implementation/src/main/java/io/smallrye/config/SmallRyeConfig.java @@ -28,7 +28,6 @@ import java.io.Serializable; import java.lang.reflect.Type; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.Comparator; @@ -361,18 +360,18 @@ public T convertValue(ConfigValue configValue, Converter converter) { // See if the Converter is designed to handle a missing (null) value i.e. Optional Converters converted = converter.convert(""); } catch (IllegalArgumentException ignored) { - throw new NoSuchElementException(ConfigMessages.msg.propertyNotFound(configValue.getNameProfiled())); // 2 + throw new NoSuchElementException(ConfigMessages.msg.propertyNotFound(configValue.getNameProfiled())); } } if (converted == null) { if (configValue.getValue() == null) { - throw new NoSuchElementException(ConfigMessages.msg.propertyNotFound(configValue.getNameProfiled())); // 2 + throw new NoSuchElementException(ConfigMessages.msg.propertyNotFound(configValue.getNameProfiled())); } else if (configValue.getValue().isEmpty()) { - throw ConfigMessages.msg.propertyEmptyString(configValue.getNameProfiled(), converter.getClass().getTypeName()); // 3 + throw ConfigMessages.msg.propertyEmptyString(configValue.getNameProfiled(), converter.getClass().getTypeName()); } else { throw ConfigMessages.msg.converterReturnedNull(configValue.getNameProfiled(), configValue.getValue(), - converter.getClass().getTypeName()); // 4 + converter.getClass().getTypeName()); } } @@ -807,7 +806,7 @@ private static List mapSources(final List getProfiles(final List interceptors) { for (ConfigSourceInterceptor interceptor : interceptors) { if (interceptor instanceof ProfileConfigSourceInterceptor) { - return Arrays.asList(((ProfileConfigSourceInterceptor) interceptor).getProfiles()); + return ((ProfileConfigSourceInterceptor) interceptor).getProfiles(); } } return Collections.emptyList();