powered by Jive Software

NumberFormatException When the Smack check the IP Domain


#1
			XMPPTCPConnectionConfiguration conf = XMPPTCPConnectionConfiguration.builder()
				     .setXmppDomain("122.20.221.11").setUsernameAndPassword("username", "password")
				     .setCompressionEnabled(false)
				     .setSecurityMode(ConnectionConfiguration.SecurityMode.required)		
				     .setCustomSSLContext(sslcont)
				     .build();

When I set the xmppDomain as a IP Address, and run the code ,the Smack 4.2.1 will error.(NumberFormatException).

I debug the source code(smack-core-4.2.1.jar IpAddressUtil.class) ,the matcher.group occur a excepiton

    private static final Pattern IPV4_PATTERN = Pattern.compile("^(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})$");

    public static boolean isIPv4LiteralAddress(String string) {
        Matcher matcher = IPV4_PATTERN.matcher(string);
        if (!matcher.matches()) {
            return false;
        }

        for (int i = 0; i < 3; i++) {
            String ipSegment = matcher.group(i);
            int ipSegmentInt;
            try {
                ipSegmentInt = Integer.valueOf(ipSegment);
            } catch (NumberFormatException e) {
                throw new AssertionError(e);
            }
            if (ipSegmentInt > 255) {
                return false;
            }
        }
        return true;
    }

The Console shows the error

Exception in thread "Smack Packet Reader (0)" java.lang.AssertionError: java.lang.NumberFormatException: For input string: "122.20.221.11" 
        at org.jivesoftware.smack.util.IpAddressUtil.isIPv4LiteralAddress(IpAddressUtil.java:38) 
        at org.jivesoftware.smack.util.IpAddressUtil.isIpAddress(IpAddressUtil.java:57) 
        at org.jivesoftware.smack.java7.XmppHostnameVerifier.match(XmppHostnameVerifier.java:101) 
        at org.jivesoftware.smack.java7.XmppHostnameVerifier.verify(XmppHostnameVerifier.java:71) 
        at org.jivesoftware.smack.tcp.XMPPTCPConnection.proceedTLSReceived(XMPPTCPConnection.java:807) 
        at org.jivesoftware.smack.tcp.XMPPTCPConnection.access$1200(XMPPTCPConnection.java:150) 
        at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.parsePackets(XMPPTCPConnection.java:1055) 
        at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.access$300(XMPPTCPConnection.java:982) 
        at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader$1.run(XMPPTCPConnection.java:998) 
        at java.lang.Thread.run(Thread.java:748)

#2

Thanks for reporting. Created SMACK-791.