in commons-testing-generic/src/main/java/org/apache/commons/testing/net/AvailableServerPortFinder.java [140:152]
public static synchronized int getNextAvailable(final int fromPort) {
if (fromPort < currentMinPort.get() || fromPort > MAX_PORT_NUMBER) {
throw new IllegalArgumentException("From port number not in valid range: " + fromPort);
}
for (int i = fromPort; i <= MAX_PORT_NUMBER; i++) {
if (available(i)) {
return i;
}
}
throw new NoSuchElementException("Could not find an available port above " + fromPort);
}