powered by Jive Software

ClassCastException in SASLAuthentication function returns wrong class

I’'m trying to use smack to access GoogleTalk service, everything would be fine except I got weird class cast exception.

This line:


Should return class that extends Packet abstract class. Instead I get PacketReader class instance…:

This is code from SASLAuthentication with some slight modifications:

Bind bindResource = new Bind();


PacketCollector collector = connection

.createPacketCollector(new PacketIDFilter(bindResource.getPacketID()));

// Send the packet


Bind response;

// Wait up to a certain number of seconds for a response from the server.

//Packet response = collector.nextResult(SmackConfiguration.getPacketReplyTimeout());

Object resp=collector.nextResult(SmackConfiguration.getPacketReplyTimeout());

System.out.println(“SASL RESPONSE CLASS:”+resp.getClass().toString());

During execution I get:

15:55:45,375 INFO Connecting to service gmail.com at talk.google.com:5222

15:55:46,078 INFO SASL RESPONSE CLASS:class org.jivesoftware.smack.PacketReader$4

I’'m using 32b JVM 1.5 on Windows XP x64 could it be tha cause of that “leak”??

That exception is thrown in private String bindResourceAndEstablishSession(String resource) function

21/2/2006 - 16:02:00

Message was edited by: baranowb

Hey Bartosz,

You might want to read the following KB document: url=http://www.jivesoftware.org/community/entry.jspa?externalID=461&categoryID=1 8Why am I getting java.lang.ClassCastException?[/url].

Hope that helps.


– Gato

Thanks Gato, but it didn’'t help. I still get PacketReader instance instead Bind instance.

I have included smack.providers in jar file:

$ jar tf smack.jar





I have added/modified those lines in buld.xml


  • <pathelement **location="$/build/resources/META-INF/smack.providers"/>

This one went to target=“compile”

**<jar destfile="${jar.dest.dir}/smack.jar"

  • basedir="${compile.dir}"

  • includes=“org/jivesoftware/smack/*/.class, **/smack-config.xml, **/smack.providers”

Ant this one is modified “jar” element from target=“jar”

Did I do something wrong?

I have posted full stack trace here: http://www.jivesoftware.org/community/thread.jspa?messageID=113965&#113965

Message was edited by: baranowb

Hey baranowb,

We found this problem SMACK-124 that was fixed today. You can use the next nightly build that will include the bug fix or just include smackx.jar in the classpath.


– Gato

Thanks for info Gaston. It didnt help. I still get that CCE:

12:17:40,593 INFO java.lang.ClassCastException: org.jivesoftware.smack.PacketReader$4

12:17:40,593 INFO at org.jivesoftware.smack.SASLAuthentication.authenticate(SASLAuthentication.java: 175)

12:17:40,593 INFO at org.jivesoftware.smack.XMPPConnection.login(XMPPConnection.java:352)

12:17:40,593 INFO at org.jivesoftware.smack.XMPPConnection.login(XMPPConnection.java:318)

12:17:40,593 INFO at org.mobicents.slee.resource.xmpp.XmppResourceAdaptor$XMPPConnectionListener.run (XmppResourceAdaptor.java:546)

12:17:40,765 INFO (405)

12:17:40,765 INFO at org.jivesoftware.smack.NonSASLAuthentication.authenticate(NonSASLAuthentication .java:62)

12:17:40,765 INFO at org.jivesoftware.smack.SASLAuthentication.authenticate(SASLAuthentication.java: 215)

12:17:40,765 INFO at org.jivesoftware.smack.XMPPConnection.login(XMPPConnection.java:352)

12:17:40,765 INFO at org.jivesoftware.smack.XMPPConnection.login(XMPPConnection.java:318)

12:17:40,765 INFO at org.mobicents.slee.resource.xmpp.XmppResourceAdaptor$XMPPConnectionListener.run (XmppResourceAdaptor.java:546)

I have even tried to overcome that CCE by changing that line from something like this:

String name=(String) it.next();

to Object name=it.next();

It didn’‘t help. Same CCE is being thrown from that line. It’'s strange because that Iterator it (it) should return Stirng Object.

Weirdest of all is that when I modify SASLAuth… so line 175 is empty, CCE still points at line 175.

smackx.jar has always been in classpath.

sorry please disgregard this post.