tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mark Leone <>
Subject Re: Surprised with this behaviour. Is this a bug ?
Date Fri, 03 Jun 2005 03:34:09 GMT
Not sure I follow all your explanation, and I think you haven't shown us 
enough of your code to know what's going on, but what is the method 
signature for method.invoke()? You're passing it an Object and an Object[].

The former (obj) is returned from requestMap.get(). Assuming requestMap 
is a Map object, the get() method returns an object of whatever type you 
pit into it, and perhaps you should downcast to this type.

The second parameter you're passing into method.invoke() is an Object 
that has been "upcasted" from the return value of 
request.getParameterMap(). That method returns an object of type 

In sum, I would look at the method signature for method.invoke(), and 
cast your arguments in that method call as needed.


nitin dubey wrote:

>>>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)	{
>Object obj	= requestMap.get("ParamKey");
>String str	= (String) obj;
>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:

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

View raw message