Smack 版本 4.2.0-rc1 XMPPTCPConnectionConfiguration setHostAddress() throws StringIndexOutOfBoundsException
Smack version 4.2.0-rc1 XMPPTCPConnectionConfiguration setHostAddress() throws StringIndexOutOfBoundsException
我们正在使用 Openfire 4.1.1 并尝试与 smack 连接,与之前的 smack 版本 4.1.9 它运行完美。
但为了实现 XEP-0313(MAP),必须更新 smack 版本 4.2.0-rc1。
这里是 XMPPTCPConnectionConfiguration,
InetAddress inetAddress = InetAddress.getByName(mServiceName);
//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();
这里的mServiceName是本地ip地址""192.168.X.X".
还有例外,
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.<init>(HostAddress.java:48)
W/System.err: at org.jivesoftware.smack.util.dns.HostAddress.<init>(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.access0(ChatConnectionServi ce.java:20)
W/System.err: at com.example.bosleo.chatapp.ChatConnectionService.run(ChatConnectionService.ja va:105)
W/System.err: at java.lang.Thread.run(Thread.java:818)
请检查 HostAddress class 构造函数。可能是因为 fdqn 值为 "".
public HostAddress(int port, InetAddress hostAddress) {
this("", port, Collections.singletonList(hostAddress));
}
public HostAddress(String fqdn, int port, List<InetAddress> 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;
}
或者万一我做错了什么,还有其他选择吗?原题 is here.
这是一个应该在 4.2.0-rc2 中修复的错误。尝试 4.2.0-rc2-SNAPSHOT 直到发布。
我们正在使用 Openfire 4.1.1 并尝试与 smack 连接,与之前的 smack 版本 4.1.9 它运行完美。 但为了实现 XEP-0313(MAP),必须更新 smack 版本 4.2.0-rc1。
这里是 XMPPTCPConnectionConfiguration,
InetAddress inetAddress = InetAddress.getByName(mServiceName);
//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();
这里的mServiceName是本地ip地址""192.168.X.X".
还有例外,
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.<init>(HostAddress.java:48)
W/System.err: at org.jivesoftware.smack.util.dns.HostAddress.<init>(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.access0(ChatConnectionServi ce.java:20)
W/System.err: at com.example.bosleo.chatapp.ChatConnectionService.run(ChatConnectionService.ja va:105)
W/System.err: at java.lang.Thread.run(Thread.java:818)
请检查 HostAddress class 构造函数。可能是因为 fdqn 值为 "".
public HostAddress(int port, InetAddress hostAddress) {
this("", port, Collections.singletonList(hostAddress));
}
public HostAddress(String fqdn, int port, List<InetAddress> 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;
}
或者万一我做错了什么,还有其他选择吗?原题 is here.
这是一个应该在 4.2.0-rc2 中修复的错误。尝试 4.2.0-rc2-SNAPSHOT 直到发布。