Hi All,

I think there is an unhandled case in
org.apache.cocoon.environment.http.HttpRequest (CVS 1.1.1.1.2.4) that causes
a null pointer exception in
org.apache.cocoon.components.language.markup.xsp.XSPCookieHelper (CVS
1.2.2.1).

XSPCookieHelper.getCookie(Map objectModel ,ContentHandler contentHandler):

        Request request =
(Request)objectModel.get(Constants.REQUEST_OBJECT);

        Cookie[] cookies = request.getCookies(); <-- can be null

        int count  = 0;

        String tempStr = null;

        Hashtable nodeTable = new Hashtable();

        if(cookies.length > 0) <-- causes NPE (XSPCookieHelper line 171)

This seems to be caused by (in HttpRequest ):

    public Cookie[] getCookies() {
        if (this.wrappedCookies == null) {
            this.wrappedCookieMap = new HashMap();
            javax.servlet.http.Cookie[] cookies = this.req.getCookies();
            if (cookies != null) {
                this.wrappedCookies = new Cookie[cookies.length];
                for(int i=0; i<cookies.length;i++) {
                    HttpCookie cookie = new HttpCookie(cookies[i]);
                    this.wrappedCookies[i] = cookie;
                    this.wrappedCookieMap.put(cookie.getName(),cookie);
                }
            }
        }
        return this.wrappedCookies;
    }

If

this.wrappedCookies == null
AND
cookies == null

then the array wrappedCookies will be return null.

Is this the desired behaviour when no cookies exist?

One solution is to test for null in XSPCookieHelper, another is to change
HttpRequest.getCookies() so something like:

    public Cookie[] getCookies() {
        if (this.wrappedCookies == null) {
            this.wrappedCookieMap = new HashMap();
            javax.servlet.http.Cookie[] cookies = this.req.getCookies();
            if (cookies != null) {
                this.wrappedCookies = new Cookie[cookies.length];
                for(int i=0; i<cookies.length;i++) {
                    HttpCookie cookie = new HttpCookie(cookies[i]);
                    this.wrappedCookies[i] = cookie;
                    this.wrappedCookieMap.put(cookie.getName(),cookie);
                }
            }
                else {
                        this.wrappedCookies = new Cookie[0];
                }

        }
        return this.wrappedCookies;
    }


This is my first post to Cocoon-dev so I'm unsure of what to do about this.
Should I submit it as a bug to BugZilla or would you like me to make the
change to HttpRequest and submit a patch?

Thanks for your time (and patience :),

Best Regards,

Chris

--
Chris Newland
Software Research Engineer

Emorphia Ltd
Registered in England.  4133002
Mill House, Station Approach, Harlow Mill, Harlow, Essex, CM20 2EL, UK

Email: [EMAIL PROTECTED]
Tel: +44 (0)1279 450100
Fax: +44 (0)1279 450102

Check out FIPA-OS at http://fipa-os.sourceforge.net/

This message may contain information proprietary to Emorphia so any
unauthorised disclosure, copying or distribution of its contents is strictly
prohibited.



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, email: [EMAIL PROTECTED]

Reply via email to