NullPointerException in EntityCapsManager.addCapsExtension

Hi,

Since we updated to smack 4.4.0 we got reported in firebase more than 50 crashes of this type.

Smack version: 4.4.0 (4.4.0-4.4 2020-12-06)

Exception: java.lang.NullPointerException
Attempt to read from field ‘java.lang.String org.jivesoftware.smackx.caps.CapsVersionAndHash.version’ on a null object reference

Stack trace:
org.jivesoftware.smackx.caps.EntityCapsManager.addCapsExtension (EntityCapsManager.java:316)
org.jivesoftware.smackx.caps.EntityCapsManager.lambda$YL7Mt7ErRxuSiuhk2xNzLeflrTY (EntityCapsManager.java)
org.jivesoftware.smackx.caps.-$$Lambda$EntityCapsManager$YL7Mt7ErRxuSiuhk2xNzLeflrTY.accept (-.java:4)
org.jivesoftware.smack.AbstractXMPPConnection.fireMessageOrPresenceInterceptors (AbstractXMPPConnection.java:1301)
org.jivesoftware.smack.AbstractXMPPConnection.firePacketInterceptors (AbstractXMPPConnection.java:1342)
org.jivesoftware.smack.AbstractXMPPConnection.sendStanza (AbstractXMPPConnection.java:879)
org.jivesoftware.smack.AbstractXMPPConnection.afterSuccessfulLogin (AbstractXMPPConnection.java:806)
org.jivesoftware.smack.tcp.XMPPTCPConnection.afterSuccessfulLogin (XMPPTCPConnection.java:371)
org.jivesoftware.smack.tcp.XMPPTCPConnection.loginInternal (XMPPTCPConnection.java:469)
org.jivesoftware.smack.AbstractXMPPConnection.login (AbstractXMPPConnection.java:641)

Code (with params simplified for readability):
XMPPTCPConnectionConfiguration.Builder configBuilder = XMPPTCPConnectionConfiguration.builder();
configBuilder.setHostAddress(host);
configBuilder.setPort(port);
configBuilder.setXmppDomain(domain);
configBuilder.setSendPresence(true);
configBuilder.setSecurityMode(SecurityMode.ifpossible);
mConnection = new XMPPTCPConnection(configBuilder.build());
mConnection.addConnectionListener(listener);
mConnection.connect();
mConnection.login(user, pass, Resourcepart.fromOrThrowUnchecked(resource));

Unfortunatelly we cannot reproduce it, neither devs nor QA, so I cannot use SmackConfiguration.DEBUG to get an XMPP trace.
But strangely enough, it did occur several times to one guy and what we found is that method
EntityCapsManager.updateLocalEntityCaps() that updated the EntityCapsManager.currentCapsVersion field was executed after the login method needed it. Probably most of the times it runs before.

We tried several things to hotfix the issue.
A Thread.sleep(500) fixed the issue locally but, as expected, it doesn’t fix it to our users.
We tried calling EntityCapsManager.getInstanceFor(mConnection).disableEntityCaps() before calling login() but this call doesn’t remove the presence interceptor from the connection.
More exactly method EntityCapsManager.enableEntityCaps() (which is executed by the lib) calls
connection().addPresenceInterceptor(this::addCapsExtension
that is
AbstractXMPPConnection.addPresenceInterceptor(presenceInterceptor)
and method EntityCapsManager.disableEntityCaps() (executed by us) calls
connection().removePresenceInterceptor(this::addCapsExtension);
that is
AbstractXMPPConnection.removePresenceInterceptor(presenceInterceptor)

but presenceInterceptor in addPresenceInterceptor is (eg) object
org.jivesoftware.smackx.caps.-$$Lambda$EntityCapsManager$YL7Mt7ErRxuSiuhk2xNzLeflrTY@16756
while in removePresenceInterceptor is
org.jivesoftware.smackx.caps.-$$Lambda$EntityCapsManager$YL7Mt7ErRxuSiuhk2xNzLeflrTY@17031
So the interceptor is not removed and the crash would occurs.

Of course, these are only hotfixes that we tried. Normally the situation should not occur, currentCapsVersion should be set before login() needs it.

My question now would be: did we do something wrong or there is a problem in the lib?

In case it helps, we have this in build.gradle:
dependencies {
implementation ‘org.igniterealtime.smack:smack-android-extensions:4.4.0’
implementation ‘org.igniterealtime.smack:smack-tcp:4.4.0’
}
configurations {
all*.exclude group: ‘xpp3’, module: ‘xpp3’
}

Thanks for reporting. I have created SMACK-899.

I think the real fix would be simply to check for null in addCapsExtension().

1 Like

Thanks for the quick fix!
When can we expect the release of 4.4.1? (to know how we handle the issue)
Is there a way to be notified when 4.4.1 is released?

I don’t provide any ETAs as part of my community support. That said, if you need the fix quickly, I can help you to get agile when it comes to integrating patches or unreleased versions of Smack into your project, or to create an release, as part of my professional support.

New releases get announced on the Ignite Realtime Blog, which also appears on igniterealtime.org.

This topic was automatically closed 62 days after the last reply. New replies are no longer allowed.