Skip to content

Commit 6da0fe7

Browse files
authored
Fix CodeQL warnings (#4431)
1 parent b2f6de5 commit 6da0fe7

File tree

2 files changed

+12
-30
lines changed

2 files changed

+12
-30
lines changed

etw/etw-testapp/src/main/java/com/microsoft/applicationinsights/etw_testapp/EtwTestController.java

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
import org.springframework.http.ResponseEntity;
44
import org.springframework.web.bind.annotation.GetMapping;
5-
import org.springframework.web.bind.annotation.PathVariable;
6-
import org.springframework.web.bind.annotation.RequestParam;
75
import org.springframework.web.bind.annotation.RestController;
86

97
import java.util.concurrent.atomic.AtomicInteger;
@@ -14,25 +12,26 @@
1412
public class EtwTestController {
1513
private static final DiagnosticsLoggerProxy DIAGNOSTICS_LOGGER = new DiagnosticsLoggerProxy();
1614

15+
private static final String LEVEL = "info";
16+
private static final boolean HAS_EXCEPTION = false;
17+
1718
private final AtomicInteger errorCount = new AtomicInteger();
1819
private final AtomicInteger warnCount = new AtomicInteger();
1920
private final AtomicInteger infoCount = new AtomicInteger();
2021

21-
@GetMapping("/{level}")
22-
public ResponseEntity<String> logPage(
23-
@PathVariable String level,
24-
@RequestParam(name = "e", required = false, defaultValue = "false") boolean hasException) {
25-
String msg = "Hit /" + level + " ";
22+
@GetMapping("/log")
23+
public ResponseEntity<String> logPage() {
24+
String msg = "Hit /" + LEVEL + " ";
2625
int n;
2726
Throwable t = null;
28-
switch (level.toLowerCase()) {
27+
switch (LEVEL.toLowerCase()) {
2928
case "info":
3029
n = infoCount.incrementAndGet();
3130
DIAGNOSTICS_LOGGER.info(msg + n);
3231
break;
3332
case "error":
3433
n = errorCount.incrementAndGet();
35-
if (hasException) {
34+
if (HAS_EXCEPTION) {
3635
t = new Exception("the error " + n);
3736
DIAGNOSTICS_LOGGER.error(msg + n, t);
3837
} else {
@@ -41,7 +40,7 @@ public ResponseEntity<String> logPage(
4140
break;
4241
case "warn":
4342
n = warnCount.incrementAndGet();
44-
if (hasException) {
43+
if (HAS_EXCEPTION) {
4544
t = new Exception("the warn " + n);
4645
DIAGNOSTICS_LOGGER.warn(msg + n, t);
4746
} else {
@@ -52,6 +51,6 @@ public ResponseEntity<String> logPage(
5251
return ResponseEntity.notFound().build();
5352
}
5453
return ResponseEntity.ok(
55-
level.toUpperCase() + " " + n + (t == null ? "" : "<br/>\n" + t.toString()));
54+
LEVEL.toUpperCase() + " " + n + (t == null ? "" : "<br/>\n" + t.toString()));
5655
}
5756
}

etw/etw-testapp/src/main/java/com/microsoft/applicationinsights/etw_testapp/LongTestController.java

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -232,29 +232,12 @@ private double rand() {
232232
}
233233

234234
@GetMapping("/start")
235-
public ResponseEntity<String> startTest(
236-
@RequestParam(name = "T", required = false, defaultValue = "1s") String periodStr) {
235+
public ResponseEntity<String> startTest() {
237236
if (future.get() != null) {
238237
return ResponseEntity.status(HttpStatus.CONFLICT).body("Test already in progress.");
239238
}
240239

241-
final Duration period;
242-
try {
243-
if (periodStr.toLowerCase().endsWith("ms")) {
244-
period = Duration.ofMillis(Long.parseLong(periodStr.substring(0, periodStr.length() - 2)));
245-
} else {
246-
period = Duration.parse("PT" + periodStr);
247-
}
248-
} catch (NumberFormatException | DateTimeParseException e) {
249-
return ResponseEntity.badRequest()
250-
.body(
251-
"<p>Period parameter 'T' could not parse \""
252-
+ periodStr
253-
+ "\"</p>"
254-
+ "<p><pre>"
255-
+ ExceptionUtils.getStackTrace(e)
256-
+ "</p>");
257-
}
240+
final Duration period = Duration.parse("PT1s");
258241

259242
final long startTime;
260243
final ScheduledFuture<?> scheduledTask;

0 commit comments

Comments
 (0)