cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Carsten Ziegeler" <cziege...@sundn.de>
Subject AW: HttpRequest.getCookies() causes NPE in XSPCookieHelper.getCookies()
Date Thu, 16 Aug 2001 12:23:12 GMT
Thanks for reporting this Chris.

I fixed it, please check if this is working now.


Carsten

Open Source Group                        sunShine - b:Integrated
================================================================
Carsten Ziegeler, S&N AG, Klingenderstrasse 5, D-33100 Paderborn
www.sundn.de                          mailto: cziegeler@sundn.de
================================================================


> -----Urspr√ľngliche Nachricht-----
> Von: Chris Newland [mailto:chris.newland@emorphia.com]
> Gesendet: Donnerstag, 16. August 2001 13:58
> An: Cocoon Dev
> Betreff: HttpRequest.getCookies() causes NPE in
> XSPCookieHelper.getCookies()
>
>
> 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: chris.newland@emorphia.com
> 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: cocoon-dev-unsubscribe@xml.apache.org
> For additional commands, email: cocoon-dev-help@xml.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: cocoon-dev-unsubscribe@xml.apache.org
For additional commands, email: cocoon-dev-help@xml.apache.org


Mime
View raw message