1818import io .micronaut .core .annotation .Nullable ;
1919
2020import java .util .HashMap ;
21+ import java .util .LinkedHashMap ;
2122import java .util .List ;
2223import java .util .Map ;
24+ import java .util .regex .Pattern ;
2325
2426/**
2527 * Loads properties from environment variables via {@link System#getenv()}.
@@ -31,7 +33,7 @@ public class EnvironmentPropertySource extends MapPropertySource {
3133 /**
3234 * Converts list elemtents defined as _0 or _0_ into names that the resolver can understand; i.e., [0].
3335 */
34- private static final String LIST_CONVERTER_REGEX = "_([0-9]{1,2})(?:_|$)" ;
36+ private static final Pattern LIST_CONVERTER_REGEX = Pattern . compile ( "_([0-9]{1,2})(?:_|$)" ) ;
3537
3638 /**
3739 * The position of the loader.
@@ -81,7 +83,7 @@ static Map getEnv(@Nullable List<String> includes, @Nullable List<String> exclud
8183 }
8284
8385 static Map getEnv (Map <String , String > env , @ Nullable List <String > includes , @ Nullable List <String > excludes ) {
84- Map <String , String > result = new HashMap <>();
86+ Map <String , String > result = new LinkedHashMap <>();
8587 for (Map .Entry <String , String > entry : env .entrySet ()) {
8688 String envVar = entry .getKey ();
8789 if (excludes != null && excludes .contains (envVar )) {
@@ -91,10 +93,11 @@ static Map getEnv(Map<String, String> env, @Nullable List<String> includes, @Nul
9193 continue ;
9294 }
9395
94- String convertedEnvVar = envVar .replaceAll (LIST_CONVERTER_REGEX , "[$1]" );
96+ String convertedEnvVar = LIST_CONVERTER_REGEX . matcher ( envVar ) .replaceAll ("[$1]" );
9597
9698 result .put (convertedEnvVar , entry .getValue ());
9799 }
100+
98101 return result ;
99102 }
100103}
0 commit comments