santafebound santafebound - 15 days ago 6
Java Question

IllegalArgumentException: Could not parse [/24] - SubnetUtils

public static void main(String[] args) {
// Comma delimited string containing all default gateways and netmask addresses
String defaultGWs = "10.255.63.254,10.229.241.254,10.139.232.254,10.229.241.254,10.229.241.254,152.73.223.254,10.229.241.254,10.229.241.254,10.96.6.254,192.168.0.1,10.139.232.254,10.96.6.254,10.229.240.254,10.96.6.254,10.229.97.254,10.255.63.254,10.229.240.254,10.229.241.254,10.229.241.254,10.230.2.1,10.96.6.254,,10.229.241.254,10.96.6.254,10.255.63.254,10.230.2.1,10.255.63.254,10.255.63.254";
String interfacesNetmasks = "255.255.255.0,255.255.255.0,255.255.255.0,255.255.255.0,255.255.255.0,255.255.255.224,255.255.255.0,255.255.255.0,255.255.255.0,255.255.255.0,255.255.255.0,255.255.255.0,255.255.255.0,255.255.255.0,255.255.255.0,255.255.255.0,255.255.255.0,255.255.255.0,255.255.255.0,255.255.255.0,255.255.255.0,255.255.255.0,255.255.0.0,,255.255.255.0,255.255.255.0,255.255.255.0,255.255.255.0";

// Format for consumption in List<String>
List<String> interfacesNetmasksList = Arrays.asList(interfacesNetmasks.split("\\s*,\\s*"));
System.out.println(interfacesNetmasksList.size());
List<String> defaultGWsList = Arrays.asList(defaultGWs.split("\\s*,\\s*"));
System.out.println(defaultGWsList.size());

// Loop through list, calculate and print subnet information for each gateway and netmask
for (int i = 0; i < (defaultGWsList).size(); i++) {
SubnetInfo subnetInfo = (new SubnetUtils(defaultGWsList.get(i), interfacesNetmasksList.get(i)).getInfo());
printSubnetInfo(subnetInfo);
}

}


I get the following error:

Exception in thread "main" java.lang.IllegalArgumentException: Could not parse [/24]
at org.apache.commons.net.util.SubnetUtils.calculate(SubnetUtils.java:275)
at org.apache.commons.net.util.SubnetUtils.<init>(SubnetUtils.java:62)
at GetSubnetInfoJava.main(GetSubnetInfoJava.java:22)


I thought that perhaps this was because I was passing in a IPv4 address that was not dot-delimited. But I'm looking at my list and I don't see one...

What's going wrong?

Answer

Output:

28
28
i: 0
defaultGWsList: 10.255.63.254
interfacesNetmasksList: 255.255.255.0
{
  "address" : "10.255.63.254",
  "broadcastAddress" : "10.255.63.255",
  "networkAddress" : "10.255.63.0",
  "highAddress" : "10.255.63.254",
  "addressCount" : 254,
  "cidrSignature" : "10.255.63.254/24",
  "allAddresses" : [ "10.255.63.1", "10.255.63.2", "10.255.63.3", "10.255.63.4", "10.255.63.5", "10.255.63.6", "10.255.63.7", "10.255.63.8", "10.255.63.9", "10.255.63.10", "10.255.63.11", "10.255.63.12", "10.255.63.13", "10.255.63.14", "10.255.63.15", "10.255.63.16", "10.255.63.17", "10.255.63.18", "10.255.63.19", "10.255.63.20", "10.255.63.21", "10.255.63.22", "10.255.63.23", "10.255.63.24", "10.255.63.25", "10.255.63.26", "10.255.63.27", "10.255.63.28", "10.255.63.29", "10.255.63.30", "10.255.63.31", "10.255.63.32", "10.255.63.33", "10.255.63.34", "10.255.63.35", "10.255.63.36", "10.255.63.37", "10.255.63.38", "10.255.63.39", "10.255.63.40", "10.255.63.41", "10.255.63.42", "10.255.63.43", "10.255.63.44", "10.255.63.45", "10.255.63.46", "10.255.63.47", "10.255.63.48", "10.255.63.49", "10.255.63.50", "10.255.63.51", "10.255.63.52", "10.255.63.53", "10.255.63.54", "10.255.63.55", "10.255.63.56", "10.255.63.57", "10.255.63.58", "10.255.63.59", "10.255.63.60", "10.255.63.61", "10.255.63.62", "10.255.63.63", "10.255.63.64", "10.255.63.65", "10.255.63.66", "10.255.63.67", "10.255.63.68", "10.255.63.69", "10.255.63.70", "10.255.63.71", "10.255.63.72", "10.255.63.73", "10.255.63.74", "10.255.63.75", "10.255.63.76", "10.255.63.77", "10.255.63.78", "10.255.63.79", "10.255.63.80", "10.255.63.81", "10.255.63.82", "10.255.63.83", "10.255.63.84", "10.255.63.85", "10.255.63.86", "10.255.63.87", "10.255.63.88", "10.255.63.89", "10.255.63.90", "10.255.63.91", "10.255.63.92", "10.255.63.93", "10.255.63.94", "10.255.63.95", "10.255.63.96", "10.255.63.97", "10.255.63.98", "10.255.63.99", "10.255.63.100", "10.255.63.101", "10.255.63.102", "10.255.63.103", "10.255.63.104", "10.255.63.105", "10.255.63.106", "10.255.63.107", "10.255.63.108", "10.255.63.109", "10.255.63.110", "10.255.63.111", "10.255.63.112", "10.255.63.113", "10.255.63.114", "10.255.63.115", "10.255.63.116", "10.255.63.117", "10.255.63.118", "10.255.63.119", "10.255.63.120", "10.255.63.121", "10.255.63.122", "10.255.63.123", "10.255.63.124", "10.255.63.125", "10.255.63.126", "10.255.63.127", "10.255.63.128", "10.255.63.129", "10.255.63.130", "10.255.63.131", "10.255.63.132", "10.255.63.133", "10.255.63.134", "10.255.63.135", "10.255.63.136", "10.255.63.137", "10.255.63.138", "10.255.63.139", "10.255.63.140", "10.255.63.141", "10.255.63.142", "10.255.63.143", "10.255.63.144", "10.255.63.145", "10.255.63.146", "10.255.63.147", "10.255.63.148", "10.255.63.149", "10.255.63.150", "10.255.63.151", "10.255.63.152", "10.255.63.153", "10.255.63.154", "10.255.63.155", "10.255.63.156", "10.255.63.157", "10.255.63.158", "10.255.63.159", "10.255.63.160", "10.255.63.161", "10.255.63.162", "10.255.63.163", "10.255.63.164", "10.255.63.165", "10.255.63.166", "10.255.63.167", "10.255.63.168", "10.255.63.169", "10.255.63.170", "10.255.63.171", "10.255.63.172", "10.255.63.173", "10.255.63.174", "10.255.63.175", "10.255.63.176", "10.255.63.177", "10.255.63.178", "10.255.63.179", "10.255.63.180", "10.255.63.181", "10.255.63.182", "10.255.63.183", "10.255.63.184", "10.255.63.185", "10.255.63.186", "10.255.63.187", "10.255.63.188", "10.255.63.189", "10.255.63.190", "10.255.63.191", "10.255.63.192", "10.255.63.193", "10.255.63.194", "10.255.63.195", "10.255.63.196", "10.255.63.197", "10.255.63.198", "10.255.63.199", "10.255.63.200", "10.255.63.201", "10.255.63.202", "10.255.63.203", "10.255.63.204", "10.255.63.205", "10.255.63.206", "10.255.63.207", "10.255.63.208", "10.255.63.209", "10.255.63.210", "10.255.63.211", "10.255.63.212", "10.255.63.213", "10.255.63.214", "10.255.63.215", "10.255.63.216", "10.255.63.217", "10.255.63.218", "10.255.63.219", "10.255.63.220", "10.255.63.221", "10.255.63.222", "10.255.63.223", "10.255.63.224", "10.255.63.225", "10.255.63.226", "10.255.63.227", "10.255.63.228", "10.255.63.229", "10.255.63.230", "10.255.63.231", "10.255.63.232", "10.255.63.233", "10.255.63.234", "10.255.63.235", "10.255.63.236", "10.255.63.237", "10.255.63.238", "10.255.63.239", "10.255.63.240", "10.255.63.241", "10.255.63.242", "10.255.63.243", "10.255.63.244", "10.255.63.245", "10.255.63.246", "10.255.63.247", "10.255.63.248", "10.255.63.249", "10.255.63.250", "10.255.63.251", "10.255.63.252", "10.255.63.253", "10.255.63.254" ],
  "netmask" : "255.255.255.0",
  "lowAddress" : "10.255.63.1"
}
// [...]
i: 20
defaultGWsList: 10.96.6.254
interfacesNetmasksList: 255.255.255.0
{
  "address" : "10.96.6.254",
  "broadcastAddress" : "10.96.6.255",
  "networkAddress" : "10.96.6.0",
  "highAddress" : "10.96.6.254",
  "addressCount" : 254,
  "cidrSignature" : "10.96.6.254/24",
  "allAddresses" : [ "10.96.6.1", "10.96.6.2", "10.96.6.3", "10.96.6.4", "10.96.6.5", "10.96.6.6", "10.96.6.7", "10.96.6.8", "10.96.6.9", "10.96.6.10", "10.96.6.11", "10.96.6.12", "10.96.6.13", "10.96.6.14", "10.96.6.15", "10.96.6.16", "10.96.6.17", "10.96.6.18", "10.96.6.19", "10.96.6.20", "10.96.6.21", "10.96.6.22", "10.96.6.23", "10.96.6.24", "10.96.6.25", "10.96.6.26", "10.96.6.27", "10.96.6.28", "10.96.6.29", "10.96.6.30", "10.96.6.31", "10.96.6.32", "10.96.6.33", "10.96.6.34", "10.96.6.35", "10.96.6.36", "10.96.6.37", "10.96.6.38", "10.96.6.39", "10.96.6.40", "10.96.6.41", "10.96.6.42", "10.96.6.43", "10.96.6.44", "10.96.6.45", "10.96.6.46", "10.96.6.47", "10.96.6.48", "10.96.6.49", "10.96.6.50", "10.96.6.51", "10.96.6.52", "10.96.6.53", "10.96.6.54", "10.96.6.55", "10.96.6.56", "10.96.6.57", "10.96.6.58", "10.96.6.59", "10.96.6.60", "10.96.6.61", "10.96.6.62", "10.96.6.63", "10.96.6.64", "10.96.6.65", "10.96.6.66", "10.96.6.67", "10.96.6.68", "10.96.6.69", "10.96.6.70", "10.96.6.71", "10.96.6.72", "10.96.6.73", "10.96.6.74", "10.96.6.75", "10.96.6.76", "10.96.6.77", "10.96.6.78", "10.96.6.79", "10.96.6.80", "10.96.6.81", "10.96.6.82", "10.96.6.83", "10.96.6.84", "10.96.6.85", "10.96.6.86", "10.96.6.87", "10.96.6.88", "10.96.6.89", "10.96.6.90", "10.96.6.91", "10.96.6.92", "10.96.6.93", "10.96.6.94", "10.96.6.95", "10.96.6.96", "10.96.6.97", "10.96.6.98", "10.96.6.99", "10.96.6.100", "10.96.6.101", "10.96.6.102", "10.96.6.103", "10.96.6.104", "10.96.6.105", "10.96.6.106", "10.96.6.107", "10.96.6.108", "10.96.6.109", "10.96.6.110", "10.96.6.111", "10.96.6.112", "10.96.6.113", "10.96.6.114", "10.96.6.115", "10.96.6.116", "10.96.6.117", "10.96.6.118", "10.96.6.119", "10.96.6.120", "10.96.6.121", "10.96.6.122", "10.96.6.123", "10.96.6.124", "10.96.6.125", "10.96.6.126", "10.96.6.127", "10.96.6.128", "10.96.6.129", "10.96.6.130", "10.96.6.131", "10.96.6.132", "10.96.6.133", "10.96.6.134", "10.96.6.135", "10.96.6.136", "10.96.6.137", "10.96.6.138", "10.96.6.139", "10.96.6.140", "10.96.6.141", "10.96.6.142", "10.96.6.143", "10.96.6.144", "10.96.6.145", "10.96.6.146", "10.96.6.147", "10.96.6.148", "10.96.6.149", "10.96.6.150", "10.96.6.151", "10.96.6.152", "10.96.6.153", "10.96.6.154", "10.96.6.155", "10.96.6.156", "10.96.6.157", "10.96.6.158", "10.96.6.159", "10.96.6.160", "10.96.6.161", "10.96.6.162", "10.96.6.163", "10.96.6.164", "10.96.6.165", "10.96.6.166", "10.96.6.167", "10.96.6.168", "10.96.6.169", "10.96.6.170", "10.96.6.171", "10.96.6.172", "10.96.6.173", "10.96.6.174", "10.96.6.175", "10.96.6.176", "10.96.6.177", "10.96.6.178", "10.96.6.179", "10.96.6.180", "10.96.6.181", "10.96.6.182", "10.96.6.183", "10.96.6.184", "10.96.6.185", "10.96.6.186", "10.96.6.187", "10.96.6.188", "10.96.6.189", "10.96.6.190", "10.96.6.191", "10.96.6.192", "10.96.6.193", "10.96.6.194", "10.96.6.195", "10.96.6.196", "10.96.6.197", "10.96.6.198", "10.96.6.199", "10.96.6.200", "10.96.6.201", "10.96.6.202", "10.96.6.203", "10.96.6.204", "10.96.6.205", "10.96.6.206", "10.96.6.207", "10.96.6.208", "10.96.6.209", "10.96.6.210", "10.96.6.211", "10.96.6.212", "10.96.6.213", "10.96.6.214", "10.96.6.215", "10.96.6.216", "10.96.6.217", "10.96.6.218", "10.96.6.219", "10.96.6.220", "10.96.6.221", "10.96.6.222", "10.96.6.223", "10.96.6.224", "10.96.6.225", "10.96.6.226", "10.96.6.227", "10.96.6.228", "10.96.6.229", "10.96.6.230", "10.96.6.231", "10.96.6.232", "10.96.6.233", "10.96.6.234", "10.96.6.235", "10.96.6.236", "10.96.6.237", "10.96.6.238", "10.96.6.239", "10.96.6.240", "10.96.6.241", "10.96.6.242", "10.96.6.243", "10.96.6.244", "10.96.6.245", "10.96.6.246", "10.96.6.247", "10.96.6.248", "10.96.6.249", "10.96.6.250", "10.96.6.251", "10.96.6.252", "10.96.6.253", "10.96.6.254" ],
  "netmask" : "255.255.255.0",
  "lowAddress" : "10.96.6.1"
}
i: 21
defaultGWsList: 
interfacesNetmasksList: 255.255.255.0
Exception in thread "main" java.lang.IllegalArgumentException: Could not parse [/24]
    at org.apache.commons.net.util.SubnetUtils.calculate(SubnetUtils.java:240)
    at org.apache.commons.net.util.SubnetUtils.<init>(SubnetUtils.java:63)

Inspecting your defaultGWsList, I found two consecutive commas at position 324. Either provide another IP address or remove a comma and a subnet mask to make your code work.