Skip to content

Commit 70e7d95

Browse files
committed
Avoid using SimpleDateFormat
1 parent 8625f8f commit 70e7d95

File tree

1 file changed

+5
-10
lines changed

1 file changed

+5
-10
lines changed

opamp-client/src/main/java/io/opentelemetry/opamp/client/internal/connectivity/http/RetryAfterParser.java

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
package io.opentelemetry.opamp.client.internal.connectivity.http;
77

88
import io.opentelemetry.opamp.client.internal.tools.SystemTime;
9-
import java.text.ParseException;
10-
import java.text.SimpleDateFormat;
119
import java.time.Duration;
10+
import java.time.ZonedDateTime;
11+
import java.time.format.DateTimeFormatter;
1212
import java.util.Locale;
1313
import java.util.regex.Pattern;
1414

@@ -18,8 +18,8 @@ public final class RetryAfterParser {
1818
public static final Pattern DATE_PATTERN =
1919
Pattern.compile(
2020
"^([A-Za-z]{3}, [0-3][0-9] [A-Za-z]{3} [0-9]{4} [0-2][0-9]:[0-5][0-9]:[0-5][0-9] GMT)$");
21-
private static final SimpleDateFormat dateFormat =
22-
new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z", Locale.US);
21+
private static final DateTimeFormatter DATE_FORMAT =
22+
DateTimeFormatter.ofPattern("EEE, dd MMM yyyy HH:mm:ss z", Locale.US);
2323

2424
public static RetryAfterParser getInstance() {
2525
return new RetryAfterParser(SystemTime.getInstance());
@@ -38,12 +38,7 @@ public Duration parse(String value) {
3838
throw new IllegalArgumentException("Invalid Retry-After value: " + value);
3939
}
4040

41-
@SuppressWarnings({"JavaUtilDate", "ThrowSpecificExceptions"})
4241
private static long toMilliseconds(String value) {
43-
try {
44-
return dateFormat.parse(value).getTime();
45-
} catch (ParseException e) {
46-
throw new RuntimeException(e);
47-
}
42+
return ZonedDateTime.parse(value, DATE_FORMAT).toInstant().toEpochMilli();
4843
}
4944
}

0 commit comments

Comments
 (0)