stanfordnlp/CoreNLP · error · IllegalArgumentException

Invalid subnet

Error message

Invalid subnet: ${subnet}

What it means

parseSubnet() parses whitelist entries of the form 'ip/prefix'. If InetAddress.getByName cannot resolve the IP portion (malformed IPv4 address), the UnknownHostException is rethrown as IllegalArgumentException naming the bad subnet string.

Solutions

  1. Fix the whitelist entry to valid CIDR form, e.g. 10.0.0.0/8 or 127.0.0.1/32
  2. Verify the IP portion resolves with `nslookup` or `ping` before adding hostnames
  3. Use prefix lengths (0-32) rather than dotted netmasks
  4. Check number of / parts: exactly ip/prefix, no extra slashes

Example fix

// before
-whitelist "192.168.1.0/255.255.255.0"
// after
-whitelist "192.168.1.0/24"
Defensive patterns

Strategy: validation

Validate before calling

for (String subnet : whitelist.split(",")) {
  String[] p = subnet.split("/");
  if (p.length != 2) throw new IllegalArgumentException("Need ip/prefix: " + subnet);
  if (!p[0].matches("(\\d{1,3}\\.){3}\\d{1,3}")) throw new IllegalArgumentException("Bad IPv4: " + subnet);
  int prefix = Integer.parseInt(p[1]);
  if (prefix < 0 || prefix > 32) throw new IllegalArgumentException("Bad prefix: " + subnet);
}

Try / catch

try {
  startServerWithWhitelist(whitelist);
} catch (IllegalArgumentException e) {
  if (e.getMessage().startsWith("Invalid subnet")) {
    log.error("Fix whitelist entry: " + e.getMessage());
    throw e; // config error, do not auto-retry
  } else throw e;
}

Prevention

When it happens

Trigger: Starting the server with -whitelist (or annotator/subnet config) containing a malformed IPv4 subnet such as '999.1.1.0/24', '10.0.0/8', or a hostname that does not resolve, with a /prefix part.

Common situations: Typos in subnet CIDR notation; using IPv6 in a slot expecting Inet4Address; copy-pasting masks like 255.255.255.0 instead of prefix length; Docker/hostnames in the whitelist that fail DNS resolution.

Understand the failure class

Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.

Related errors


AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10). Data as JSON: /api/errors/f2e3c4a6057e302c. Report an issue: GitHub.

Appendix: source

Thrown at src/edu/stanford/nlp/pipeline/StanfordCoreNLPServer.java:653


  /**
   * Adapted from: https://stackoverflow.com/questions/4209760/validate-an-ip-address-with-mask
   */
  private static Pair<Inet4Address, Integer> parseSubnet(String subnet) {
    String[] parts = subnet.split("/");
    String ip = parts[0];
    int prefix;

    if (parts.length < 2) {
      prefix = 0;
    } else {
      prefix = Integer.parseInt(parts[1]);
    }
    try {
      return Pair.makePair((Inet4Address) InetAddress.getByName(ip), prefix);
    } catch (UnknownHostException e) {
      throw new IllegalArgumentException("Invalid subnet: " + subnet);
    }
  }


  /**
   * Adapted from: https://stackoverflow.com/questions/4209760/validate-an-ip-address-with-mask
   */
  @SuppressWarnings("PointlessBitwiseExpression")
  private static boolean netMatch(Pair<Inet4Address, Integer> subnet, Inet4Address addr ){
    byte[] b = subnet.first.getAddress();
    int ipInt = ((b[0] & 0xFF) << 24) |
        ((b[1] & 0xFF) << 16) |
        ((b[2] & 0xFF) << 8)  |
        ((b[3] & 0xFF) << 0);
    byte[] b1 = addr.getAddress();
    int ipInt1 = ((b1[0] & 0xFF) << 24) |
        ((b1[1] & 0xFF) << 16) |
        ((b1[2] & 0xFF) << 8)  |

View on GitHub (pinned to 1b7edd19c4)