public void validate(Cookie cookie, CookieOrigin cookieorigin) throws MalformedCookieException { if (cookie == null) { throw new IllegalArgumentException("Cookie may not be null"); } if (cookieorigin == null) { throw new IllegalArgumentException("Cookie origin may not be null"); } String s = cookieorigin.getHost(); cookieorigin = cookie.getDomain(); if (cookieorigin == null) { throw new CookieRestrictionViolationException("Cookie domain may not be null"); } if (s.contains(".")) { if (!s.endsWith(cookieorigin)) { cookie = cookieorigin; if (cookieorigin.startsWith(".")) { cookie = cookieorigin.substring(1, cookieorigin.length()); } if (!s.equals(cookie)) { throw new CookieRestrictionViolationException( (new StringBuilder()) .append("Illegal domain attribute \"") .append(cookie) .append("\". Domain of origin: \"") .append(s) .append("\"") .toString()); } } } else if (!s.equals(cookieorigin)) { throw new CookieRestrictionViolationException( (new StringBuilder()) .append("Illegal domain attribute \"") .append(cookieorigin) .append("\". Domain of origin: \"") .append(s) .append("\"") .toString()); } }