Skip to content

Commit

Permalink
Use ConcurrentHashMap for thread safety.
Browse files Browse the repository at this point in the history
  • Loading branch information
p4paul committed Jan 25, 2022
1 parent 35f8858 commit 5c5410b
Showing 1 changed file with 4 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,16 @@
import org.jenkinsci.plugins.p4.credentials.P4BaseCredentials;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.TimeUnit;
import java.util.logging.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;

import static com.perforce.p4java.common.base.ObjectUtils.nonNull;

public class SessionHelper extends CredentialsHelper {

private static Logger logger = Logger.getLogger(SessionHelper.class.getName());
Expand All @@ -44,7 +43,7 @@ public class SessionHelper extends CredentialsHelper {
private IOptionsServer connection;
private boolean abort = false;

private static Map<String, SessionEntry> loginCache = new HashMap<>();
private static ConcurrentMap<String, SessionEntry> loginCache = new ConcurrentHashMap<>();

public SessionHelper(P4BaseCredentials credential, TaskListener listener) throws IOException {
super(credential, listener);
Expand Down Expand Up @@ -312,7 +311,7 @@ private boolean isLogin() throws Exception {
List<Map<String, Object>> resultMaps = connection.execMapCmdList(CmdSpec.LOGIN, new String[]{"-s"}, null);
String ticket = connection.getAuthTicket();

if (nonNull(resultMaps) && !resultMaps.isEmpty()) {
if (resultMaps != null && !resultMaps.isEmpty()) {
for (Map<String, Object> map : resultMaps) {
String status = ResultMapParser.getInfoStr(map);
if (status == null) {
Expand Down

0 comments on commit 5c5410b

Please sign in to comment.