hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Oleg Kalnichevski <ol...@apache.org>
Subject Re: "java.lang.ClassCastException : java.lang.Long cannot be cast to java.lang.Integer" is thrown from getIntParameter() method in AbstrastHttpParams.java(part of httpcore)
Date Thu, 17 Oct 2013 08:05:36 GMT
On Thu, 2013-10-17 at 11:38 +0530, Dhruva Kumar wrote:
> I was using HttpClient 4.0.1 in my web application to communicate with
> different servers, specifically used httpclient-4.0.1.jar,
> httpcore-4.0.1.jar and httpmime-4.0.1.jar. 
> Everything was working without any issues.
> Now I have upgraded the library to HttpClient 4.3.1
> (httpclient-4.3.1.jar, httpcore-4.3.jar & httpmime-4.3.1.jar).
> I had to change my workspace code to resolve all the compilation
> errors because of the library upgradation.
> But when my application is trying to establish a HTTP connection with
> other server, "java.lang.ClassCastException : java.lang.Long cannot be
> cast to java.lang.Integer" is thrown from getIntParameter() method in
> AbstrastHttpParams.java(part of httpcore).
> 
> 
> Implementation of getIntParameter() is as follows :
> public int getIntParameter(final String name, final int defaultValue)
> {
>         final Object param = getParameter(name);
>         if (param == null) {
>             return defaultValue;
>         }
>         return ((Integer) param).intValue();
>     }
> 
> 
> When this method is invoked from HttpClientParamConfig's
> setConnectionRequestTimeout()  to get the value
> for ClientPNames.CONN_MANAGER_TIMEOUT,
> getIntParameter() throws ClassCastException because param object is
> assigned with Long typed object and casting it to Integer type
>   reference : ((Integer) param).intValue()
> 
> 
> 
> I see the following statements in ClientPNames.java
>      * This parameter expects a value of type {@link Long}.
>      * @since 4.2
> 
>     public static final String CONN_MANAGER_TIMEOUT =
> "http.conn-manager.timeout";
> 
> 
> 
> 
> 
> If the parameter is of type Long, then why is
> setConnectionRequestTimeout() calling getIntParameter() rather than
> calling getLongParameter() ?
> Am I missing something here ?
> 
> 
> 
> Would you recommend any suggestions to resolve this issue ?
> 
> 
> Thanks in advance,
> Dhruva

This is a known issue [1] which has already been resolved in SVN trunk.
The best way to get rid of it is to make sure your code does not use any
deprecated functionality

Oleg

[1] https://issues.apache.org/jira/browse/HTTPCLIENT-1418


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org


Mime
View raw message