powered by Jive Software

Smack version 4.2.0-rc1 XMPPTCPConnectionConfiguration setHostAddress() throws StringIndexOutOfBoundsException.

We’re working with Openfire 4.1.1 and trying to connect with smack, with previous smack version 4.1.9 it was working perfectly.

But in order to achieve XEP-0313(MAP), has to update with smack version 4.2.0-rc1.

Here is XMPPTCPConnectionConfiguration,

InetAddress inetAddress = InetAddress.getByName(mServiceName);

or

InetAddress inetAddress = InetAddress.getLocalHost();

XMPPTCPConnectionConfiguration xmpptcpConnectionConfiguration =

XMPPTCPConnectionConfiguration.builder()

.setXmppDomain(mServiceName)

.setUsernameAndPassword(mUsername, mPassword)

.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled)

.setHostAddress(inetAddress)

.setPort(5222)

.setDebuggerEnabled(true)

.setSendPresence(true)

.setDebuggerEnabled(true)

.setCompressionEnabled(true)

.build();

Here mServiceName is local ip address "“192.168.X.X”.

And exception,

W/System.err: java.lang.StringIndexOutOfBoundsException: length=0; index=-1

W/System.err: at java.lang.String.charAt(Native Method)

W/System.err: at org.jivesoftware.smack.util.dns.HostAddress.(HostAddress.java:48)

W/System.err: at org.jivesoftware.smack.util.dns.HostAddress.(HostAddress.java:62)

W/System.err: at org.jivesoftware.smack.AbstractXMPPConnection.populateHostAddresses(AbstractXMP PConnection.java:607)

W/System.err: at org.jivesoftware.smack.tcp.XMPPTCPConnection.connectUsingConfiguration(XMPPTCPC onnection.java:555)

W/System.err: at org.jivesoftware.smack.tcp.XMPPTCPConnection.connectInternal(XMPPTCPConnection. java:885)

W/System.err: at org.jivesoftware.smack.AbstractXMPPConnection.connect(AbstractXMPPConnection.ja va:374)

W/System.err: at com.example.bosleo.chatapp.ChatConnection.connect(ChatConnection.java:141)

W/System.err: at com.example.bosleo.chatapp.ChatConnectionService.initConnection(ChatConnectionS ervice.java:82)

W/System.err: at com.example.bosleo.chatapp.ChatConnectionService.access$100(ChatConnectionServi ce.java:20)

W/System.err: at com.example.bosleo.chatapp.ChatConnectionService$1.run(ChatConnectionService.ja va:105)

W/System.err: at java.lang.Thread.run(Thread.java:818)

Please check with HostAddress class constructors. May be it’s because fdqn value is “”.

public HostAddress(int port, InetAddress hostAddress) {

this("", port, Collections.singletonList(hostAddress));

}

public HostAddress(String fqdn, int port, List inetAddresses) {

Objects.requireNonNull(fqdn, “FQDN is null”);

if (port < 0 || port > 65535)

throw new IllegalArgumentException(

"Port must be a 16-bit unsiged integer (i.e. between 0-65535. Port was: " + port);

if (fqdn.charAt(fqdn.length() - 1) == ‘.’) {

this.fqdn = fqdn.substring(0, fqdn.length() - 1);

}

else {

this.fqdn = fqdn;

}

this.port = port;

if (inetAddresses.isEmpty()) {

throw new IllegalArgumentException(“Must provide at least one InetAddress”);

}

this.inetAddresses = inetAddresses;

}

Or in case I’m doing something wrong, request smack team to provide alternative asap. Many thanks in advance.

If I set .setHost(mServiceName) , it throws below exception.

W/System.err: java.lang.IllegalStateException: Can not perform operation because the DNS resolution was unsuccessful

W/System.err: at de.measite.minidns.hla.ResolverResult.throwIseIfErrorResponse(ResolverResult.ja va:113)

W/System.err: at de.measite.minidns.hla.ResolverResult.getAnswers(ResolverResult.java:56)

W/System.err: at org.jivesoftware.smack.util.dns.minidns.MiniDnsResolver.lookupHostAddress0(Mini DnsResolver.java:130)

W/System.err: at org.jivesoftware.smack.util.dns.DNSResolver.lookupHostAddress(DNSResolver.java: 52)

W/System.err: at org.jivesoftware.smack.AbstractXMPPConnection.populateHostAddresses(AbstractXMP PConnection.java:612)

W/System.err: at org.jivesoftware.smack.tcp.XMPPTCPConnection.connectUsingConfiguration(XMPPTCPC onnection.java:555)

W/System.err: at org.jivesoftware.smack.tcp.XMPPTCPConnection.connectInternal(XMPPTCPConnection. java:885)

W/System.err: at org.jivesoftware.smack.AbstractXMPPConnection.connect(AbstractXMPPConnection.ja va:374)

W/System.err: at com.example.bosleo.chatapp.ChatConnection.connect(ChatConnection.java:147)

W/System.err: at com.example.bosleo.chatapp.ChatConnectionService.initConnection(ChatConnectionS ervice.java:82)

W/System.err: at com.example.bosleo.chatapp.ChatConnectionService.access$100(ChatConnectionServi ce.java:20)

W/System.err: at com.example.bosleo.chatapp.ChatConnectionService$1.run(ChatConnectionService.ja va:105)

W/System.err: at java.lang.Thread.run(Thread.java:818)

W/System.err: Caused by: de.measite.minidns.hla.ResolutionUnsuccessfulException: Asking for 192.168.2.128. IN AAAA yielded an error response NX_DOMAIN

W/System.err: at de.measite.minidns.hla.ResolverResult.getResolutionUnsuccessfulException(Resolv erResult.java:89)

W/System.err: at de.measite.minidns.hla.ResolverResult.throwIseIfErrorResponse(ResolverResult.ja va:111)

W/System.err: … 12 more

Thanks for reporting. I’ve uploaded 4.2.0-rc2-SNAPSHOT containing MiniDNS resolver: Fix exception when there is only a A or AAAA RR · Flowdalic/Smack@b343b49 · GitHub , please test and report back if it fixes the issue.

Thanks for quick fix. But it seems 4.2.0-rc2-SNAPSHOT is not available for gradle version.

Did you add Maven Central’s snapshot repository to your project?

Yes, I’ve added below statements for that,

maven {

url ‘https://oss.sonatype.org/content/repositories/snapshots
}

mavenCentral()

Any thing else requires for that?

Sir, any update for this?

Dunno, all I can say is that it is here: https://oss.sonatype.org/content/repositories/snapshots/org/igniterealtime/smack /smack-core/4.2.0-rc2-SNAPSHOT/

My bad, need to put maven in allprojects block instead of buildscript block of project’s build.gradle.

allprojects {

repositories {

jcenter()

maven {

url ‘https://oss.sonatype.org/content/repositories/snapshots
}

mavenCentral()

}

}

And yes, I’m able to do login now.

Many thanks for wonderful support.