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().
Created attachment 18023 [details] patch to Util.java getRequestLocale
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().
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.