• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

alibaba / java-dns-cache-manipulator / 1267

pending completion
1267

push

Appveyor

oldratlee
chore(ci): upgrade CI JDK 🤖

527 of 645 relevant lines covered (81.71%)

0.82 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

66.67
/library/src/main/java/com/alibaba/dcm/internal/IpParserUtil.java
1
package com.alibaba.dcm.internal;
2

3
/**
4
 * @author Jerry Lee (oldratlee at gmail dot com)
5
 */
6
final class IpParserUtil {
7
    private static final String INVALID_IP_V6_ADDRESS = ": invalid IPv6 address";
8
    private static final String INVALID_IP_ADDRESS = ": invalid IP address";
9

10
    /**
11
     * source code is dug from {@link java.net.InetAddress#getAllByName(java.lang.String, java.net.InetAddress)}
12
     */
13
    static byte[] ip2ByteArray(String ip) {
14
        boolean ipv6Expected = false;
1✔
15
        if (ip.charAt(0) == '[') {
1✔
16
            // This is supposed to be an IPv6 literal
17
            if (ip.length() > 2 && ip.charAt(ip.length() - 1) == ']') {
×
18
                ip = ip.substring(1, ip.length() - 1);
×
19
                ipv6Expected = true;
×
20
            } else {
21
                // This was supposed to be a IPv6 address, but it's not!
22
                throw new IllegalArgumentException(ip + INVALID_IP_V6_ADDRESS);
×
23
            }
24
        }
25

26
        if (Character.digit(ip.charAt(0), 16) != -1 || (ip.charAt(0) == ':')) {
1✔
27
            // see if it is IPv4 address
28
            byte[] address = IPAddressUtil.textToNumericFormatV4(ip);
1✔
29
            if (address != null) return address;
1✔
30

31
            // see if it is IPv6 address
32
            // Check if a numeric or string zone id is present
33
            address = IPAddressUtil.textToNumericFormatV6(ip);
1✔
34
            if (address != null) return address;
1✔
35

36
            if (ipv6Expected) {
1✔
37
                throw new IllegalArgumentException(ip + INVALID_IP_V6_ADDRESS);
×
38
            } else {
39
                throw new IllegalArgumentException(ip + INVALID_IP_ADDRESS);
1✔
40
            }
41
        } else {
42
            throw new IllegalArgumentException(ip + INVALID_IP_ADDRESS);
1✔
43
        }
44
    }
45

46

47
    private IpParserUtil() {
48
    }
49
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc