tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nitin dubey <>
Subject Surprised with this behaviour. Is this a bug ?
Date Thu, 02 Jun 2005 18:33:03 GMT

>From a servlet deployed in tomcat I am getting the
request parameter map by calling getParameterMap()
then using reflection calling a Class say "Sub" that
has a method "construct(HashMap requestMap)".  The
method is called properly but surprisingly I am
getting InvocationTargetException->ClassCastException
when I try to read the parameter from the map. 
Following is the code.

======== Code in Class called from Servlet ====
// Note that the map instance is an instance of
Method method	= cls.getMethod("constructSql", new

query	= (String) method.invoke(obj, new

======== Code from Sub ============
public String construct(HashMap requestMap)	{"~construct()");"10");
Object obj	= requestMap.get("ParamKey");;"10.1");
String str	= (String) obj;;"10.2");

return "";

======== Console Output ==========
INFO  [http-8080-Processor25] SearchCodeQuery     -
INFO  [http-8080-Processor25] SearchCodeQuery     - 10
INFO  [http-8080-Processor25] SearchCodeQuery     -
class [Ljava.lang.String;
INFO  [http-8080-Processor25] SearchCodeQuery     -
INFO  [http-8080-Processor25] ServletRequestProcessor 
   - java.lang.reflect.InvocationTargetException
INFO  [http-8080-Processor25] ServletRequestProcessor 
   - java.lang.ClassCastException: [Ljava.lang.String;

Is it because that the instance is actually
org.apache.catalina.util.ParameterMap and I am trying
to call get() over that instance ?  But ParameterMap
itself does not have any implementation of get() it
takes that from its superclass i.e. HashMap.

Is it not supposed to run.  When you can see in the
log that the value is a String object and a similar
java application using LinkedHashMap and HashMap runs
without any hiccups ?

I am using JDK:1.5.0_03, Tomcat:5.5.9

Thanks in advance


Discover Yahoo! 
Find restaurants, movies, travel and more fun for the weekend. Check it out! 

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message