[Demonstration 1]

[Buggy Method]
public void put(URI uri, Headers headers) {
    maybeInit();
    try {
        manager.put(uri, headers.getMultiMap());
        // no cookies to persist.
        if (headers.get("Set-Cookie") == null)
            return;
        List<HttpCookie> cookies = manager.getCookieStore().get(uri);
        Headers dump = new Headers();
        for (HttpCookie cookie : cookies) {
            dump.add("Set-Cookie", cookie.getName() + "=" + cookie.getValue());
        }
        String key = uri.getScheme() + "://" + uri.getAuthority();
        preferences.edit().putString(key, dump.toPrefixString("HTTP/1.1 200 OK")).commit();
    } catch (Exception e) {
    }
}

[Buggy Hunk]
dump.add("Set-Cookie", cookie.getName() + "=" + cookie.getValue());

[Patch]
dump.add("Set-Cookie", cookie.getName() + "=" + cookie.getValue() + "; path=" + cookie.getPath());

[Demonstration 2]

[Buggy Method]
private JSONObject getStateFromCookie(javax.servlet.http.Cookie cookie) {
    if (cookie == null) {
        log.debug("Cookie state was <null>");
        return null;
    }
    // cookie view data
    try {
        String value = URLDecoder.decode(cookie.getValue());
        if (!value.isEmpty()) {
            log.debug("Using cookie state:", value);
            return new JSONObject(value);
        }
    } catch (Exception je) {
        log.warn("Got cookie but couldnt transform to JSON", cookie);
    }
    return null;
}

[Buggy Hunk]
String value = URLDecoder.decode(cookie.getValue());

[Patch]
String value = URLDecoder.decode(cookie.getValue(),"UTF-8");

[Demonstration 3]

[Buggy Method]
public StaffTO add(StaffTO staff) throws InterruptedException {
    StaffTO duplicateStaffNum = checkDuplicateStaffNumExists(staff);
    StaffTO duplicateLoginId = checkDuplicateLoginIdExists(staff);
    DepartmentTO departmentExists = staff.getDepartment();
    if (duplicateStaffNum == null) {
        throw new InterruptedException("1");
    }
    if (duplicateLoginId == null) {
        throw new InterruptedException("2");
    }
    if (departmentExists != null) {
        DepartmentTO department = departmentDAO.findById(departmentExists.getId());
        if (department == null) {
            throw new InterruptedException("3");
        }
    }
    staffDAO.save(staff);
    return staff;
}

[Buggy Hunk]
DepartmentTO departmentExists = staff.getDepartment();

[Patch]
DepartmentTO departmentExists = departmentDAO.findById(staff.getDeptId());