Resolve pattern COOKIE_USAGE after run FindBugs

28 Views Asked by At

I have run FindBugs for my company's project on Eclise and got bugs about COOKIE_USAGE. This my code:

public static String getCookie(HttpServletRequest request) {
    Cookie[] cookies = request.getCookies();
    StringBuilder strBuilder = new StringBuilder();
    if (cookies != null) {
        int cookieCount = cookies.length;
        for (int i = 0; i < cookieCount; i++) {
            if (cookies[i] != null) {
                String cookieName = cookies[i].getName();
                String cookieValue = cookies[i].getValue();
                strBuilder.append(cookieName).append("=").append(cookieValue).append(";");
            }
        }
    }
    return strBuilder.toString();
}

The error code is: cookies[i].getName() or cookies[i].getValue(). I really dont understand why it is bug because just get somthing from cookie variable :(. I have search some solution like check cookie is not null, set secure is true... . I dont have any idea but keeping research. Hope some one can help

0

There are 0 best solutions below