In Glassfish 2.1, when we mix Generics with auto-boxing of variables, the JSP compiler throws an exception. To reproduce the problem you can do the following. <br/> <br/>
In a web application create a java class say, "Macros.java" with the following method : <br/><br/>
package com.tests; <br/><br/>
import javax.servlet.http.HttpServletRequest; <br/><br/>
public class Macros { <br/><br/>
@SuppressWarnings("unchecked")<br/>
public static <T> T attr(String attribute, HttpServletRequest request){<br/>
return (T)request.getAttribute(attribute);<br/>
}<br/><br/>
}<br/>
<br/><br/>
The JSP is:<br/><br/>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "
http://www.w3.org/TR/html4/loose.dtd"> <br/>
<%_at_page contentType="text/html;charset=utf-8" session="false"%> <br/><br/>
<%_at_page import="com.tests.Macros"%><br/><br/>
<%<br/><br/>
request.setAttribute("integer", 24);<br/>
[b]int a = RestMacros.attr("integer", request);<br/><br/>[/b]
%><br/><br/>
<html><br/>
<head><br/>
<title>GlassFish Test Page</title><br/>
</head><br/>
<body><br/>
<h2>Test Attributes</h2><br/>
<ul><br/>
<li><%=a %></li><br/>
</ul><br/>
</body><br/>
</html><br/><br/>
You get a compilation error : <br/>
PWC6033: Unable to compile class for JSP PWC6197<br/>
type parameters of T cannot be determined; no unique maximal instance exists for type <br/>variable T with upper bounds int,java.lang.Object <br/><br/>
However, when you change <br/><br/>
int a = RestMacros.attr("integer", request); --> Integer a = RestMacros.attr("integer", request); <br/><br/>
there is no error. This is a bug in Glassfish 2.1. Are they any known workarounds / patches? <br/><br/>
Thanks, <br/>
Rahul
[Message sent by forum member 'tikurahul' ]
http://forums.java.net/jive/thread.jspa?messageID=375259