Bug 39195 - getRequestLocale could throw exception on JBOSS
Summary: getRequestLocale could throw exception on JBOSS
Status: RESOLVED FIXED
Alias: None
Product: Taglibs
Classification: Unclassified
Component: Standard Taglib (show other bugs)
Version: nightly
Hardware: Other Linux
: P2 normal (vote)
Target Milestone: ---
Assignee: Tomcat Developers Mailing List
URL:
Keywords: PatchAvailable
Depends on:
Blocks:
 
Reported: 2006-04-04 03:33 UTC by zou bin
Modified: 2007-03-27 12:22 UTC (History)
0 users



Attachments
patch to Util.java getRequestLocale (615 bytes, patch)
2006-04-04 03:35 UTC, zou bin
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description zou bin 2006-04-04 03:33:14 UTC
When I use standard taglibs in jsp to setResourceBundle I get an
exception on JBOSS(it's good on jetspeed2). I found this is because
getRequestLocale in Util.java use  request.getHeaders("accept-language")  to get
a values(Enumeration), and expected this values to be not null.
But servlet api said "If the container does not allow access to header
information, return null". I guess this is the case in JBOSS. So I add a check
for values and return request.getLocales() when values is null, the problem
resolved. The following is the patch:


*** standard/src/org/apache/taglibs/standard/tag/common/core/Util.java
2006-04-02 16:12:11.000000000 +0800
--- Util.java.new	2006-04-03 12:11:59.000000000 +0800
***************
*** 278,283 ****
--- 278,286 ----
       */
      public static Enumeration getRequestLocales(HttpServletRequest request) {
       
          Enumeration values = request.getHeaders("accept-language");
+ 		if(values == null){
+ 			return request.getLocales();
+ 		}
          if (values.hasMoreElements()) {
              // At least one "accept-language". Simply return
              // the enumeration returned by request.getLocales().
Comment 1 zou bin 2006-04-04 03:35:11 UTC
Created attachment 18023 [details]
patch to Util.java getRequestLocale
Comment 2 Henri Yandell 2006-12-27 14:10:01 UTC
The javadoc says:

"a String containing the value of the requested header, or null  if the request
does not have a header of that name"

http://java.sun.com/products/servlet/2.2/javadoc/javax/servlet/http/HttpServletRequest.html#getHeader(java.lang.String)

So null protecting here seems fine. I'm not sure that the fix below makes sense
though - reading the source it looks more likely that an empty enumeration
should be returned and not request.getLocales().
Comment 3 Henri Yandell 2007-03-27 12:22:44 UTC
I'm fixing this by returning a new empty enumeration when there's a null
accept-language header:

Index: src/org/apache/taglibs/standard/tag/common/core/Util.java
===================================================================
--- src/org/apache/taglibs/standard/tag/common/core/Util.java   (revision 523035)
+++ src/org/apache/taglibs/standard/tag/common/core/Util.java   (working copy)
@@ -278,6 +278,12 @@
      */
     public static Enumeration getRequestLocales(HttpServletRequest request) { 
      
         Enumeration values = request.getHeaders("accept-language");
+        if (values == null) {
+            // No header for "accept-language". Simply return
+            // a new empty enumeration.
+            // System.out.println("Null accept-language");
+            return new Vector().elements();
+        } else
         if (values.hasMoreElements()) {
             // At least one "accept-language". Simply return
             // the enumeration returned by request.getLocales(). 




svn ci -m "Fixing the issue raised in 39195. It's legal for a null request
header to come back.
 " src/org/apache/taglibs/standard/tag/common/core/Util.java 
Sending        src/org/apache/taglibs/standard/tag/common/core/Util.java
Transmitting file data .
Committed revision 523043.

svn ci -m "Adding missing import for Vector"
src/org/apache/taglibs/standard/tag/common/core/Ut
il.java 
Sending        src/org/apache/taglibs/standard/tag/common/core/Util.java
Transmitting file data .
Committed revision 523045.