You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@activemq.apache.org by nlif <na...@dbnet.co.il> on 2007/04/30 22:26:06 UTC

ClassCastException on MessageObject's object

Hi all,

We have a strange problem, maybe someone has seen this or has an idea:

In our MessageListener, we cast the Message into ObejctMessage, and then
call getObject() to get the actual object we sent. Upon trying to cast the
object to the proper class (SendMobileNotification), we get a
ClassCastException. To make things even more strange, this is sporadic: it
doesn't always happen, and we can't figure out the exact circumstances under
which it does happen.

Here is the relevant code:

public void onMessage(Message message) {
		try {
			ObjectMessage objectMessage = (ObjectMessage) message;
                        
                        Serializable object = objectMessage.getObject();

			logger.debug("Message SHOULD BE type: " +
SendMobileNotification.class.getName() + " [hashcode=" +
SendMobileNotification.class.hashCode() + " , serialVersionUID=" +
SendMobileNotification.serialVersionUID + "]");

			logger.debug("Message IS type: " + object.getClass().getName() + "
[hashcode=" + object.getClass().hashCode() + "]");

			SendMobileNotification  sendMobileNotification = (SendMobileNotification)
(object); // this line throws ClassCastException

And here's what's written to the log:

DEBUG - Message SHOULD BE type: com.softcom.messages.SendMobileNotification
[hashcode=4050691 , serialVersionUID=-11111111111111]

DEBUG - Message IS type: com.softcom.messages.SendMobileNotification
[hashcode=31922829]


Is this an ActiveMQ issue?
Is this a class loader issue? If so, how can something like this happen?
Is it related to Serialization?

Any help will be appreciated.

Thanks,
Naaman
-- 
View this message in context: http://www.nabble.com/ClassCastException-on-MessageObject%27s-object-tf3671759s2354.html#a10260020
Sent from the ActiveMQ - User mailing list archive at Nabble.com.


Re: ClassCastException on MessageObject's object

Posted by nlif <na...@dbnet.co.il>.
James,

We assume that the class is loaded when ActiveMQObjectMessage.getObject() is
called, and the de-serialization takes place. Is this correct? Now, after
looking at the code, it seems that the class loader is resolved in
ClassLoadingAwareObjectInputStream. Is this correct? What can cause it to
use the fallback class-loader?

Thanks,
Naaman


James.Strachan wrote:
> 
> If you get a ClassCastException yet the object seems to be of the
> correct class name, then it looks like a class loader issue (multiple
> versions of the same class on the classpath). Otherwise if it was a
> serialization issue, you wouldn't get an object you can inspect.
> 
> 
> On 4/30/07, nlif <na...@dbnet.co.il> wrote:
>>
>> Hi all,
>>
>> We have a strange problem, maybe someone has seen this or has an idea:
>>
>> In our MessageListener, we cast the Message into ObejctMessage, and then
>> call getObject() to get the actual object we sent. Upon trying to cast
>> the
>> object to the proper class (SendMobileNotification), we get a
>> ClassCastException. To make things even more strange, this is sporadic:
>> it
>> doesn't always happen, and we can't figure out the exact circumstances
>> under
>> which it does happen.
>>
>> Here is the relevant code:
>>
>> public void onMessage(Message message) {
>>                 try {
>>                         ObjectMessage objectMessage = (ObjectMessage)
>> message;
>>
>>                         Serializable object = objectMessage.getObject();
>>
>>                         logger.debug("Message SHOULD BE type: " +
>> SendMobileNotification.class.getName() + " [hashcode=" +
>> SendMobileNotification.class.hashCode() + " , serialVersionUID=" +
>> SendMobileNotification.serialVersionUID + "]");
>>
>>                         logger.debug("Message IS type: " +
>> object.getClass().getName() + "
>> [hashcode=" + object.getClass().hashCode() + "]");
>>
>>                         SendMobileNotification  sendMobileNotification =
>> (SendMobileNotification)
>> (object); // this line throws ClassCastException
>>
>> And here's what's written to the log:
>>
>> DEBUG - Message SHOULD BE type:
>> com.softcom.messages.SendMobileNotification
>> [hashcode=4050691 , serialVersionUID=-11111111111111]
>>
>> DEBUG - Message IS type: com.softcom.messages.SendMobileNotification
>> [hashcode=31922829]
>>
>>
>> Is this an ActiveMQ issue?
>> Is this a class loader issue? If so, how can something like this happen?
>> Is it related to Serialization?
>>
>> Any help will be appreciated.
>>
>> Thanks,
>> Naaman
>> --
>> View this message in context:
>> http://www.nabble.com/ClassCastException-on-MessageObject%27s-object-tf3671759s2354.html#a10260020
>> Sent from the ActiveMQ - User mailing list archive at Nabble.com.
>>
>>
> 
> 
> -- 
> James
> -------
> http://macstrac.blogspot.com/
> 
> 

-- 
View this message in context: http://www.nabble.com/ClassCastException-on-MessageObject%27s-object-tf3671759s2354.html#a10265145
Sent from the ActiveMQ - User mailing list archive at Nabble.com.


Re: ClassCastException on MessageObject's object

Posted by nlif <na...@dbnet.co.il>.
Thanks, Christopher,

No, it's not. The broker and the consumer are on two different machines. The
transport is TCP.
We use Jencks for the consumer.
We're currently on ActiveMQ 4.1, but we had this problem on 4.0 as well.

Naaman



Christopher G. Stach II wrote:
> 
> nlif wrote:
>> Thanks, James.
>> 
>> Yes, I'm also inclined to think it's a class loader issue. But then, how
>> come it doesn't happen all the time?
>> What may cause it to load another version of the class only some of the
>> times?
>> Does ActiveMQ do anything... um, unconventional with class-loading?
>> 
>> Thanks,
>> Naaman
>> 
>> 
>> James.Strachan wrote:
>>> If you get a ClassCastException yet the object seems to be of the
>>> correct class name, then it looks like a class loader issue (multiple
>>> versions of the same class on the classpath). Otherwise if it was a
>>> serialization issue, you wouldn't get an object you can inspect.
>>>
>> 
> 
> Is it a vm broker?
> 
> -- 
> Christopher G. Stach II
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/ClassCastException-on-MessageObject%27s-object-tf3671759s2354.html#a10264968
Sent from the ActiveMQ - User mailing list archive at Nabble.com.


Re: ClassCastException on MessageObject's object

Posted by "Christopher G. Stach II" <cg...@ldsys.net>.
nlif wrote:
> Thanks, James.
> 
> Yes, I'm also inclined to think it's a class loader issue. But then, how
> come it doesn't happen all the time?
> What may cause it to load another version of the class only some of the
> times?
> Does ActiveMQ do anything... um, unconventional with class-loading?
> 
> Thanks,
> Naaman
> 
> 
> James.Strachan wrote:
>> If you get a ClassCastException yet the object seems to be of the
>> correct class name, then it looks like a class loader issue (multiple
>> versions of the same class on the classpath). Otherwise if it was a
>> serialization issue, you wouldn't get an object you can inspect.
>>
> 

Is it a vm broker?

-- 
Christopher G. Stach II


Re: ClassCastException on MessageObject's object

Posted by nlif <na...@dbnet.co.il>.
Thanks, James.

Yes, I'm also inclined to think it's a class loader issue. But then, how
come it doesn't happen all the time?
What may cause it to load another version of the class only some of the
times?
Does ActiveMQ do anything... um, unconventional with class-loading?

Thanks,
Naaman


James.Strachan wrote:
> 
> If you get a ClassCastException yet the object seems to be of the
> correct class name, then it looks like a class loader issue (multiple
> versions of the same class on the classpath). Otherwise if it was a
> serialization issue, you wouldn't get an object you can inspect.
> 

-- 
View this message in context: http://www.nabble.com/ClassCastException-on-MessageObject%27s-object-tf3671759s2354.html#a10264576
Sent from the ActiveMQ - User mailing list archive at Nabble.com.


Re: ClassCastException on MessageObject's object

Posted by James Strachan <ja...@gmail.com>.
If you get a ClassCastException yet the object seems to be of the
correct class name, then it looks like a class loader issue (multiple
versions of the same class on the classpath). Otherwise if it was a
serialization issue, you wouldn't get an object you can inspect.


On 4/30/07, nlif <na...@dbnet.co.il> wrote:
>
> Hi all,
>
> We have a strange problem, maybe someone has seen this or has an idea:
>
> In our MessageListener, we cast the Message into ObejctMessage, and then
> call getObject() to get the actual object we sent. Upon trying to cast the
> object to the proper class (SendMobileNotification), we get a
> ClassCastException. To make things even more strange, this is sporadic: it
> doesn't always happen, and we can't figure out the exact circumstances under
> which it does happen.
>
> Here is the relevant code:
>
> public void onMessage(Message message) {
>                 try {
>                         ObjectMessage objectMessage = (ObjectMessage) message;
>
>                         Serializable object = objectMessage.getObject();
>
>                         logger.debug("Message SHOULD BE type: " +
> SendMobileNotification.class.getName() + " [hashcode=" +
> SendMobileNotification.class.hashCode() + " , serialVersionUID=" +
> SendMobileNotification.serialVersionUID + "]");
>
>                         logger.debug("Message IS type: " + object.getClass().getName() + "
> [hashcode=" + object.getClass().hashCode() + "]");
>
>                         SendMobileNotification  sendMobileNotification = (SendMobileNotification)
> (object); // this line throws ClassCastException
>
> And here's what's written to the log:
>
> DEBUG - Message SHOULD BE type: com.softcom.messages.SendMobileNotification
> [hashcode=4050691 , serialVersionUID=-11111111111111]
>
> DEBUG - Message IS type: com.softcom.messages.SendMobileNotification
> [hashcode=31922829]
>
>
> Is this an ActiveMQ issue?
> Is this a class loader issue? If so, how can something like this happen?
> Is it related to Serialization?
>
> Any help will be appreciated.
>
> Thanks,
> Naaman
> --
> View this message in context: http://www.nabble.com/ClassCastException-on-MessageObject%27s-object-tf3671759s2354.html#a10260020
> Sent from the ActiveMQ - User mailing list archive at Nabble.com.
>
>


-- 
James
-------
http://macstrac.blogspot.com/