Bug 48612 - java.net.Inet4Address cannot be cast to java.lang.String
Summary: java.net.Inet4Address cannot be cast to java.lang.String
Status: RESOLVED FIXED
Alias: None
Product: Tomcat 6
Classification: Unclassified
Component: Catalina (show other bugs)
Version: 6.0.24
Hardware: PC Linux
: P2 normal (vote)
Target Milestone: default
Assignee: Tomcat Developers Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-01-25 14:44 UTC by Tim McCune
Modified: 2010-02-18 10:47 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tim McCune 2010-01-25 14:44:47 UTC
When I stop Tomcat, I get the following error message:

2010-01-25 14:33:52,891 ERROR [org.apache.catalina.mbeans.ServerLifecycleListener] destroyMBeans: Throwable
javax.management.MalformedObjectNameException: Cannot create object name for org.apache.catalina.connector.Connector@1d49247 java.lang.ClassCastException: java.net.Inet4Address cannot be cast to java.lang.String
  at org.apache.catalina.mbeans.MBeanUtils.createObjectName(MBeanUtils.java:758)
  at org.apache.catalina.mbeans.MBeanUtils.destroyMBean(MBeanUtils.java:1412)
  at org.apache.catalina.mbeans.ServerLifecycleListener.destroyMBeans(ServerLifecycleListener.java:678)
  at org.apache.catalina.mbeans.ServerLifecycleListener.destroyMBeans(ServerLifecycleListener.java:1005)
  at org.apache.catalina.mbeans.ServerLifecycleListener.destroyMBeans(ServerLifecycleListener.java:971)
  at org.apache.catalina.mbeans.ServerLifecycleListener.lifecycleEvent(ServerLifecycleListener.java:154)
  at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
  at org.apache.catalina.core.StandardServer.stop(StandardServer.java:748)
  at org.apache.catalina.startup.Catalina.stop(Catalina.java:643)
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
  at java.lang.reflect.Method.invoke(Method.java:597)
  at org.apache.catalina.startup.Bootstrap.stop(Bootstrap.java:301)
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
  at java.lang.reflect.Method.invoke(Method.java:597)
  at org.apache.commons.daemon.support.DaemonLoader.stop(DaemonLoader.java:200)

There are actually 2 errors here; the problem that is causing the exception shown above, and the fact that the catch block that logs the exception is swallowing the original exception and stack trace.

I changed:

} catch (Exception e) {
  throw new MalformedObjectNameException("Cannot create object name for " + connector + e);
}

to

} catch (Exception e) {
   MalformedObjectNameException tim = new MalformedObjectNameException
       ("Cannot create object name for " + connector);
   tim.initCause(e);
   throw tim;
}

and determined the actual cause of the exception:

Caused by: java.lang.ClassCastException: java.net.Inet4Address cannot be cast to java.lang.String
  at org.apache.catalina.mbeans.MBeanUtils.createObjectName(MBeanUtils.java:745)

MBeanUtils.java line 745 looks like this:

String address = (String)
                IntrospectionUtils.getProperty(connector, "address");

The "address" property on the Http 1.1 connector is indeed of type Inet4Address, and not of type String.  In the Tomcat 6.0.20 source, the line above was wrapped inside of the following check:

if (connector.getClass().getName().indexOf("CoyoteConnector") >= 0 ) {

on line 737.  In the Tomcat 6.0.24 source, this check was removed, and this causes the exception reported above.

Here is my <Connector> element from my server.xml if that helps:

<Connector allowTrace="false" emptySessionPath="false" enableLookups="false" maxPostSize="2097152" maxSavePostSize="4096" redirectPort="-1" scheme="http" secure="false" URIEncoding="UTF-8" acceptCount="100" address="0.0.0.0" bufferSize="2048" compressableMimeType="text/html,text/xml,text/plain" compression="off" connectionLinger="-1" connectionTimeout="20000" disableUploadTimeout="true" maxHttpHeaderSize="8192" maxKeepAliveRequests="1" maxSpareThreads="50" maxThreads="200" minSpareThreads="4" noCompressionUserAgents="" port="4080" restrictedUserAgents="" socketBuffer="9000" strategy="ms" tcpNoDelay="true" threadPriority="java.lang.Thread#NORM_PRIORITY" server="Apache"/>
Comment 1 Mark Thomas 2010-02-01 09:40:44 UTC
This was already fixed in trunk by the fix for bug48424. I have fixed the swallowed exception in trunk and proposed both fixes for 6.0.x
Comment 2 Mark Thomas 2010-02-18 10:47:55 UTC
This has been fixed in 6.0.x and will be included in 6.0.25 onwards.