The JavaDoc for cookies.get(String) says it returns "null if this map contains no mapping for the key". Please check for null in this line and the following 2.