[grid] Allowing -1 as port to use a random port
Fixes
private static final Logger LOG = Logger.getLogger(BaseServerOptions.class.getName());
private final Config config;
- private int port = -1;
public BaseServerOptions(Config config) {
this.config = config;
@@ -54,17 +53,14 @@ public BaseServerOptions(Config config) {
@ManagedAttribute(name = "Port")
public int getPort() {
- if (port == -1) {
- int newPort = config.getInt(SERVER_SECTION, "port")
+ int port = config.getInt(SERVER_SECTION, "port")
.orElseGet(PortProber::findFreePort);
-
- if (newPort < 0) {
- throw new ConfigException("Port cannot be less than 0: " + newPort);
+ if (port == -1) {
+ return PortProber.findFreePort();
}
-
- port = newPort;
+ if (port < 0) {
+ throw new ConfigException("Port cannot be less than 0: " + port);
}
-
return port;
}
