Skip to content

Commit 5d3e769

Browse files
Copilottrask
andcommitted
Fix TimeInStaticInitializer ErrorProne violations by moving time-dependent code out of static initializer
Co-authored-by: trask <[email protected]>
1 parent 6ad2c29 commit 5d3e769

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

buildSrc/src/main/kotlin/ai.errorprone-conventions.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ tasks {
7070
disable("YodaCondition")
7171

7272
// New checks in ErrorProne 2.37.0 that we want to disable
73-
disable("TimeInStaticInitializer")
73+
// TimeInStaticInitializer check fixed - no longer disabled
7474

7575
// New checks in ErrorProne 2.38.0 that we want to disable
7676
disable("AddNullMarkedToPackageInfo")

smoke-tests/framework/src/main/java/com/microsoft/applicationinsights/smoketest/fakeingestion/MockedProfilerSettingsServlet.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,13 @@
1717

1818
public class MockedProfilerSettingsServlet extends HttpServlet {
1919

20-
private static final Map<ProfilerState, String> CONFIGS;
21-
22-
static {
20+
private static Map<ProfilerState, String> getConfigs() {
2321
String now =
2422
DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(OffsetDateTime.now(ZoneOffset.ofHours(0)));
2523

26-
CONFIGS = new HashMap<>();
24+
Map<ProfilerState, String> configs = new HashMap<>();
2725

28-
CONFIGS.put(
26+
configs.put(
2927
ProfilerState.unconfigured,
3028
"{\n"
3129
+ " \"agentConcurrency\" : 0,\n"
@@ -39,7 +37,7 @@ public class MockedProfilerSettingsServlet extends HttpServlet {
3937
+ " \"memoryTriggerConfiguration\" : \"--memory-threshold 80 --memory-trigger-profilingDuration 120 --memory-trigger-cooldown 14400 --memory-trigger-enabled true\"\n"
4038
+ "}\n");
4139

42-
CONFIGS.put(
40+
configs.put(
4341
ProfilerState.configuredEnabled,
4442
"{\n"
4543
+ " \"agentConcurrency\" : 0,\n"
@@ -57,7 +55,7 @@ public class MockedProfilerSettingsServlet extends HttpServlet {
5755
+ " \"memoryTriggerConfiguration\" : \"--memory-threshold 80 --memory-trigger-profilingDuration 120 --memory-trigger-cooldown 14400 --memory-trigger-enabled true\"\n"
5856
+ "}\n");
5957

60-
CONFIGS.put(
58+
configs.put(
6159
ProfilerState.configuredDisabled,
6260
"{\n"
6361
+ " \"agentConcurrency\" : 0,\n"
@@ -77,7 +75,7 @@ public class MockedProfilerSettingsServlet extends HttpServlet {
7775

7876
long expire = toSeconds(Instant.now().plusSeconds(100));
7977

80-
CONFIGS.put(
78+
configs.put(
8179
ProfilerState.manualprofile,
8280
"{\n"
8381
+ " \"agentConcurrency\" : 0,\n"
@@ -96,6 +94,8 @@ public class MockedProfilerSettingsServlet extends HttpServlet {
9694
+ "\",\n"
9795
+ " \"memoryTriggerConfiguration\" : \"--memory-threshold 80 --memory-trigger-profilingDuration 120 --memory-trigger-cooldown 14400 --memory-trigger-enabled true\"\n"
9896
+ "}\n");
97+
98+
return configs;
9999
}
100100

101101
private static long toSeconds(Instant time) {
@@ -105,8 +105,9 @@ private static long toSeconds(Instant time) {
105105

106106
@Override
107107
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
108+
Map<ProfilerState, String> configs = getConfigs();
108109
Optional<Map.Entry<ProfilerState, String>> entry =
109-
CONFIGS.entrySet().stream()
110+
configs.entrySet().stream()
110111
.filter(
111112
it ->
112113
("/" + it.getKey().name() + "/api/profileragent/v4/settings")

0 commit comments

Comments
 (0)