Skip to content

Commit e0f020b

Browse files
Code review comments
1 parent 97c314b commit e0f020b

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

inject/src/main/java/io/micronaut/context/env/EnvironmentPropertySource.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@
1818
import io.micronaut.core.annotation.Nullable;
1919

2020
import java.util.HashMap;
21+
import java.util.LinkedHashMap;
2122
import java.util.List;
2223
import 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

Comments
 (0)