hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dhruva Kumar <dpg...@gmail.com>
Subject "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 06:08:30 GMT
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
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 =

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,

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message