Program: 39106
Project: 39106
Buggy source:
public static UserDetails getUserDetails(HttpServletRequest httpRequest){
  ApplicationConfigProvider.performSystemCheck();
  String authHeader=httpRequest.getHeader("String_Node_Str");
  Cookie[] requestCookies=httpRequest.getCookies();
  Map<String,String> grafanaResponseCookies=new HashMap<String,String>();
  Map<String,String> cookieMap=new HashMap<String,String>();
  if (requestCookies != null) {
    for (    Cookie cookie : requestCookies) {
      cookieMap.put(cookie.getName(),cookie.getValue());
    }
  }
  String userName=null;
  String credential=null;
  try {
    String decodedAuthHeader=new String(Base64.getDecoder().decode(authHeader.split("String_Node_Str")[1]),"String_Node_Str");
    String[] authTokens=decodedAuthHeader.split("String_Node_Str");
    userName=authTokens[0];
    credential=authTokens[1];
    String grafanaUser=cookieMap.get("String_Node_Str");
    if (userName.equals(grafanaUser)) {
      grafanaResponseCookies.putAll(cookieMap);
      if ((grafanaResponseCookies.get("String_Node_Str") == null || grafanaResponseCookies.get("String_Node_Str").isEmpty()) && (grafanaResponseCookies.get("String_Node_Str") == null || grafanaResponseCookies.get("String_Node_Str").isEmpty())) {
        Map<String,String> headers=new HashMap<String,String>();
        StringBuffer grafanaCookie=new StringBuffer();
        for (        Map.Entry<String,String> cookie : grafanaResponseCookies.entrySet()) {
          grafanaCookie.append(cookie.getKey()).append("String_Node_Str").append(cookie.getValue()).append("String_Node_Str");
        }
        headers.put("String_Node_Str",grafanaCookie.toString());
        String grafanaCurrentOrg=getGrafanaCurrentOrg(headers);
        grafanaResponseCookies.put("String_Node_Str",grafanaCurrentOrg);
        String grafanaCurrentOrgRole=getCurrentOrgRole(headers,grafanaCurrentOrg);
        grafanaResponseCookies.put("String_Node_Str",grafanaCurrentOrgRole);
      }
    }
 else {
      List<NewCookie> cookies=getValidGrafanaSession(authTokens[0],authTokens[1]);
      StringBuffer grafanaCookie=new StringBuffer();
      for (      NewCookie cookie : cookies) {
        grafanaResponseCookies.put(cookie.getName(),cookie.getValue());
        grafanaCookie.append(cookie.getName()).append("String_Node_Str").append(cookie.getValue()).append("String_Node_Str");
      }
      Map<String,String> headers=new HashMap<String,String>();
      headers.put("String_Node_Str",grafanaCookie.toString());
      String grafanaCurrentOrg=getGrafanaCurrentOrg(headers);
      grafanaResponseCookies.put("String_Node_Str",grafanaCurrentOrg);
      String grafanaCurrentOrgRole=getCurrentOrgRole(headers,grafanaCurrentOrg);
      grafanaResponseCookies.put("String_Node_Str",grafanaCurrentOrgRole);
    }
  }
 catch (  Exception e) {
    log.error(e);
  }
  List<GrantedAuthority> mappedAuthorities=new ArrayList<GrantedAuthority>();
  String grafanaRole=grafanaResponseCookies.get("String_Node_Str");
  if (grafanaRole == null || grafanaRole.trim().length() == 0) {
    mappedAuthorities.add(SpringAuthority.valueOf("String_Node_Str"));
  }
 else {
    mappedAuthorities.add(SpringAuthority.valueOf(grafanaRole));
  }
  httpRequest.setAttribute("String_Node_Str",grafanaResponseCookies);
  if (ApplicationConfigProvider.getInstance().isEnableNativeUsers()) {
    return new User(userName,credential,true,true,true,true,mappedAuthorities);
  }
 else {
    return new User(userName,"String_Node_Str",true,true,true,true,mappedAuthorities);
  }
}

Fixed version (ground truth):
public static UserDetails getUserDetails(HttpServletRequest httpRequest){
  ApplicationConfigProvider.performSystemCheck();
  String authHeader=httpRequest.getHeader("String_Node_Str");
  Cookie[] requestCookies=httpRequest.getCookies();
  Map<String,String> grafanaResponseCookies=new HashMap<String,String>();
  Map<String,String> cookieMap=new HashMap<String,String>();
  if (requestCookies != null) {
    for (    Cookie cookie : requestCookies) {
      cookieMap.put(cookie.getName(),cookie.getValue());
    }
  }
  String userName=null;
  String credential=null;
  try {
    String decodedAuthHeader=new String(Base64.getDecoder().decode(authHeader.split("String_Node_Str")[1]),"String_Node_Str");
    String[] authTokens=decodedAuthHeader.split("String_Node_Str");
    userName=authTokens[0];
    credential=authTokens[1];
    String grafanaUser=cookieMap.get("String_Node_Str");
    if (userName.equals(grafanaUser)) {
      grafanaResponseCookies.putAll(cookieMap);
      if ((grafanaResponseCookies.get("String_Node_Str") == null || grafanaResponseCookies.get("String_Node_Str").isEmpty()) && (grafanaResponseCookies.get("String_Node_Str") == null || grafanaResponseCookies.get("String_Node_Str").isEmpty())) {
        Map<String,String> headers=new HashMap<String,String>();
        StringBuffer grafanaCookie=new StringBuffer();
        for (        Map.Entry<String,String> cookie : grafanaResponseCookies.entrySet()) {
          grafanaCookie.append(cookie.getKey()).append("String_Node_Str").append(cookie.getValue()).append("String_Node_Str");
        }
        headers.put("String_Node_Str",grafanaCookie.toString());
        String grafanaCurrentOrg=getGrafanaCurrentOrg(headers);
        grafanaResponseCookies.put("String_Node_Str",grafanaCurrentOrg);
        String grafanaCurrentOrgRole=getCurrentOrgRole(headers,grafanaCurrentOrg);
        grafanaResponseCookies.put("String_Node_Str",grafanaCurrentOrgRole);
      }
    }
 else {
      List<NewCookie> cookies=getValidGrafanaSession(authTokens[0],authTokens[1]);
      StringBuffer grafanaCookie=new StringBuffer();
      for (      NewCookie cookie : cookies) {
        grafanaResponseCookies.put(cookie.getName(),cookie.getValue());
        grafanaCookie.append(cookie.getName()).append("String_Node_Str").append(cookie.getValue()).append("String_Node_Str");
      }
      Map<String,String> headers=new HashMap<String,String>();
      headers.put("String_Node_Str",grafanaCookie.toString());
      String grafanaCurrentOrg=getGrafanaCurrentOrg(headers);
      grafanaResponseCookies.put("String_Node_Str",grafanaCurrentOrg);
      String grafanaCurrentOrgRole=getCurrentOrgRole(headers,grafanaCurrentOrg);
      grafanaResponseCookies.put("String_Node_Str",grafanaCurrentOrgRole);
    }
    List<GrantedAuthority> mappedAuthorities=new ArrayList<GrantedAuthority>();
    String grafanaRole=grafanaResponseCookies.get("String_Node_Str");
    if (grafanaRole == null || grafanaRole.trim().length() == 0) {
      mappedAuthorities.add(SpringAuthority.valueOf("String_Node_Str"));
    }
 else {
      mappedAuthorities.add(SpringAuthorityUtil.getSpringAuthorityRole(grafanaRole));
    }
    httpRequest.setAttribute("String_Node_Str",grafanaResponseCookies);
    if (ApplicationConfigProvider.getInstance().isEnableNativeUsers()) {
      return new User(userName,credential,true,true,true,true,mappedAuthorities);
    }
 else {
      return new User(userName,"String_Node_Str",true,true,true,true,mappedAuthorities);
    }
  }
 catch (  Exception e) {
    log.error(e);
  }
  return null;
}