powered by Jive Software

How to define FCM server properly

Using 4.2-rc1 (java) I create a connection to Firebase Cloud Messaging (FCM) with configuration:

XMPPTCPConnectionConfiguration.Builder config = XMPPTCPConnectionConfiguration.builder();
connection = new XMPPTCPConnection(config.build());

This throws an error:

Caused by: java.lang.StringIndexOutOfBoundsException: String index out of range: -1

at java.lang.String.charAt(String.java:658)

at org.jivesoftware.smack.util.dns.HostAddress.(HostAddress.java:48)

at org.jivesoftware.smack.util.dns.HostAddress.(HostAddress.java:62)

Apparently this is because HostAddress is calling a constructor (line 48) with a string as “” - which can never work because the constructor operates on the string:

if(fqdn.charAt(fqdn.length() - 1) == 46) {

I guess this is a bug to be resolved, but is there a workaround?

Thanks for reporting. Should be fixed with Fix OOB exception when setHostAddress(InetAddress) is used. · Flowdalic/Smack@e9bbe9a · GitHub

I guess this is a bug to be resolved, but is there a workaround?

Try using setHost(String) instead of setHostAddress(InetAddress). Your config looks good so far. You can drop the setSecurityMode() as it will have no affect on TLS-right-away XMPP connections.

1 Like

Thanks Flow.

I did in fact have this before:


However, two things that made me change to InetAddress. Firstly 4.2 migration guide says this (but maybe doesn’t apply here?)

In previous versions of Smack, ConnectionConfiguration.setHost(String) could be used to set the XMPP service’s host IP address. This is no longer possible due to the added DNSSEC support. You have to use the new connection configuration ConnectionConfiguration.setHostAddress(InetAddress) instead.

Link: Smack 4.2 Readme and Upgrade Guide · igniterealtime/Smack Wiki · GitHub

Secondly if I do user setHost, I get the following error (which doesn’t occur with InetAddress):

Caused by: java.lang.NullPointerException

at org.jivesoftware.smack.AbstractXMPPConnection.populateHostAddresses(AbstractXMP PConnection.java:612)

at org.jivesoftware.smack.tcp.XMPPTCPConnection.connectUsingConfiguration(XMPPTCPC onnection.java:555)

at org.jivesoftware.smack.tcp.XMPPTCPConnection.connectInternal(XMPPTCPConnection. java:885)

at org.jivesoftware.smack.AbstractXMPPConnection.connect(AbstractXMPPConnection.ja va:374)

(caused by DNSUtil.getDNSResolver returning null)

setHost indeed worked in 4.1.9, however I upgraded because Smack seemed to just give up sending messages to FCM after a while (upgrading in the hope it was a bug that was fixed). I will detail that bug separately.


Firstly 4.2 migration guide says this (but maybe doesn’t apply here?)
It only says that setHost() can no longer be used to set IP addresses, you can still call it with a DNS name.

caused by DNSUtil.getDNSResolver returning null
Which means that no DNS resolver was set, which is mostly caused by users not following the instructions of the README causing the classpath to miss components required by Smack.

which readme? I don’t see any reference to DNS resolver

@Manish Can you please help me with this, Smack version 4.2.0-rc1 XMPPTCPConnectionConfiguration setHostAddress() throws StringIndexOutOfBoundsException.