Hello everyone,
I was retriving VCards just fine with
VCard vcard = new VCard();
vcard.load(connection, jid);
but if the user does not have VCard stored on server, Smack prints in console "No VCard for testbot@jabbim.cz" and then throws a NullPointerException.
As I was looking into source code I found in VCard.java:
privatevoid doLoad(Connection connection, String user) throws XMPPException { setType(Type.GET); PacketCollector collector = connection.createPacketCollector( new PacketIDFilter(getPacketID())); connection.sendPacket(this); VCard result = null; try{ result = (VCard) collector.nextResult(SmackConfiguration.getPacketReplyTimeout()); if (result == null) { String errorMessage = "Timeout getting VCard information"; thrownew XMPPException(errorMessage, new XMPPError( XMPPError.Condition.request_timeout, errorMessage)); } if (result.getError() != null) { thrownew XMPPException(result.getError()); } } catch (ClassCastException e) { System.out.println("No VCard for " + user); } copyFieldsFrom(result); }
The problem is the exception(NullPointerException), which is thrown on the last line. As I see it, "copyFieldsFrom(result);" should be in the try block and no exception will be thrown. Maybe also XMPPException should be thrown from the catch block instead of the System.out to signal no VCard.
Does it make sense?
Best regards
Matus Zamborsky