public static List<HttpCookie> decodeCookies(List<String> cookieStrs)
  {
    List<HttpCookie> cookies = new ArrayList<>();
    if (cookieStrs == null)
    {
      return cookies;
    }

    for (String cookieStr : cookieStrs)
    {
      if (cookieStr == null)
      {
        continue;
      }
      StringTokenizer tokenizer = new StringTokenizer(cookieStr, ";");
      String nameValuePair;

      HttpCookie cookieToBeAdd = null;
      while (tokenizer.hasMoreTokens())
      {
        nameValuePair = tokenizer.nextToken();

        int index = nameValuePair.indexOf('=');
        if (index != -1)
        {
          String name = nameValuePair.substring(0, index).trim();
          String value = stripOffSurrounding(nameValuePair.substring(index + 1).trim());
          if (name.charAt(0) != '$')
          {
            if (cookieToBeAdd != null)
            {
              cookies.add(cookieToBeAdd);
            }
            cookieToBeAdd = new HttpCookie(name, value);
          }
          else if (cookieToBeAdd != null)
          {
            if (name.equals("$Path"))
            {
              cookieToBeAdd.setPath(value);
            }
            else if (name.equals("$Domain"))
            {
              cookieToBeAdd.setDomain(value);
            }
            else if (name.equals("$Port"))
            {
              cookieToBeAdd.setPortlist(value);
            }
          }
        }
        else
        {
          throw new IllegalArgumentException("Invalid cookie name-value pair");
        }
      }
      if (cookieToBeAdd != null)
      {
        cookies.add(cookieToBeAdd);
      }
    }
    return cookies;
  }
@Test
  public void testInvalidCookieFromClient()
  {
    cookieA.setComment("nothing important");
    List<String> encodeStrs = Collections.singletonList("$Domain=.linkedin.com; $Port=80;  $Path=/; $Version=0;");
    List<HttpCookie> cookieList = CookieUtil.decodeCookies(encodeStrs);

    Assert.assertEquals(0, cookieList.size());
  }