diff options
author | Matthias Sohn <matthias.sohn@sap.com> | 2020-11-29 21:43:51 +0100 |
---|---|---|
committer | Christian Halstrick <christian.halstrick@sap.com> | 2020-12-17 17:18:11 +0100 |
commit | f29668f7a089443a0b35adb98b432e24e86d48b1 (patch) | |
tree | 60147700902a50c4e1db9c34573f1e671b27be4d /org.eclipse.jgit.lfs/src/org/eclipse/jgit | |
parent | 5b16f32de06aa59dbfdc6b0a49b0423ab408f99d (diff) | |
download | jgit-f29668f7a089443a0b35adb98b432e24e86d48b1.tar.gz jgit-f29668f7a089443a0b35adb98b432e24e86d48b1.zip |
[spotbugs] parse time using thread-safe DateTimeFormatter
LfsConnectionFactory used a static SimpleDateFormat which isn't
thread-safe. Use DateTimeFormatter instead to fix this.
Change-Id: Id580251c999e1e412c269f37b29860d310124c89
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
Diffstat (limited to 'org.eclipse.jgit.lfs/src/org/eclipse/jgit')
-rw-r--r-- | org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/internal/LfsConnectionFactory.java | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/internal/LfsConnectionFactory.java b/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/internal/LfsConnectionFactory.java index 7a0ed456c1..e221913bea 100644 --- a/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/internal/LfsConnectionFactory.java +++ b/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/internal/LfsConnectionFactory.java @@ -18,7 +18,9 @@ import java.io.IOException; import java.net.ProxySelector; import java.net.URISyntaxException; import java.net.URL; -import java.text.SimpleDateFormat; +import java.time.LocalDateTime; +import java.time.ZoneOffset; +import java.time.format.DateTimeFormatter; import java.util.LinkedList; import java.util.Map; import java.util.TreeMap; @@ -258,8 +260,8 @@ public class LfsConnectionFactory { private static final class AuthCache { private static final long AUTH_CACHE_EAGER_TIMEOUT = 500; - private static final SimpleDateFormat ISO_FORMAT = new SimpleDateFormat( - "yyyy-MM-dd'T'HH:mm:ss.SSSX"); //$NON-NLS-1$ + private static final DateTimeFormatter ISO_FORMAT = DateTimeFormatter + .ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSX"); //$NON-NLS-1$ /** * Creates a cache entry for an authentication response. @@ -278,8 +280,10 @@ public class LfsConnectionFactory { - AUTH_CACHE_EAGER_TIMEOUT; } else if (action.expiresAt != null && !action.expiresAt.isEmpty()) { - this.validUntil = ISO_FORMAT.parse(action.expiresAt) - .getTime() - AUTH_CACHE_EAGER_TIMEOUT; + this.validUntil = LocalDateTime + .parse(action.expiresAt, ISO_FORMAT) + .atZone(ZoneOffset.UTC).toInstant().toEpochMilli() + - AUTH_CACHE_EAGER_TIMEOUT; } else { this.validUntil = System.currentTimeMillis(); } |