You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@turbine.apache.org by qu...@apache.org on 2003/01/17 17:44:55 UTC
cvs commit: jakarta-turbine-2/src/java/org/apache/turbine/util/parser DefaultCookieParser.java
quintonm 2003/01/17 08:44:55
Modified: src/java/org/apache/turbine/util/parser
DefaultCookieParser.java
Log:
Patch supplied by dvandegrift@bluearc.com for Issue #TTWS11
setRunData() in DefaultCookieParser.java will throw a NullPointerException if the HttpRequest does not yet have any cookies associated with it.
According to the Servlet Spec, HttpServletRequest.getCookies() retuns null if no cookies are defined.
Cookie[] cookies = data.getRequest().getCookies();
The existing code immediately accesses cookies.length. But since cookies is null an NPE is throw.
- adds a variable 'cookiesLength' and sets it's value by checking for null first.
- removes a the redundant line:
cookiePath = new DynamicURI(data);
Revision Changes Path
1.5 +11 -10 jakarta-turbine-2/src/java/org/apache/turbine/util/parser/DefaultCookieParser.java
Index: DefaultCookieParser.java
===================================================================
RCS file: /home/cvs/jakarta-turbine-2/src/java/org/apache/turbine/util/parser/DefaultCookieParser.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- DefaultCookieParser.java 4 Jan 2003 03:56:34 -0000 1.4
+++ DefaultCookieParser.java 17 Jan 2003 16:44:55 -0000 1.5
@@ -55,6 +55,7 @@
*/
import javax.servlet.http.Cookie;
+
import org.apache.turbine.util.CookieParser;
import org.apache.turbine.util.DynamicURI;
import org.apache.commons.logging.Log;
@@ -139,7 +140,7 @@
*
* @param data the RunData object.
*/
- public void setRunData (RunData data)
+ public void setRunData(RunData data)
{
clear();
@@ -148,18 +149,18 @@
cookiePath = new DynamicURI(data);
- cookiePath = new DynamicURI(data);
-
Cookie[] cookies = data.getRequest().getCookies();
- log.debug("Number of Cookies " + cookies.length);
+ int cookiesCount = (cookies != null ? cookies.length : 0);
+
+ log.debug("Number of Cookies " + cookiesCount);
- for (int i = 0; i < cookies.length; i++)
+ for(int i = 0; i < cookiesCount; i++)
{
String name = convert(cookies[i].getName());
String value = cookies[i].getValue();
log.debug("Adding " + name + "=" + value);
- add(name,value);
+ add(name, value);
}
this.data = data;
@@ -187,7 +188,7 @@
*/
public void set(String name, String value)
{
- set(name,value,AGE_SESSION);
+ set(name, value, AGE_SESSION);
}
/**
@@ -196,7 +197,7 @@
*/
public void set(String name, String value, int seconds_age)
{
- if (data == null)
+ if(data == null)
{
throw new IllegalStateException("RunData not available");
}
@@ -212,6 +213,6 @@
*/
public void unset(String name)
{
- set(name," ",AGE_DELETE);
+ set(name, " ", AGE_DELETE);
}
}
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>