Don't allow list elements to be null.

This commit is contained in:
akwizgran
2020-03-11 17:19:09 +00:00
parent 5567982fb4
commit 6fb4b95b18

View File

@@ -43,7 +43,6 @@ import javax.annotation.Nullable;
import javax.annotation.concurrent.GuardedBy; import javax.annotation.concurrent.GuardedBy;
import javax.annotation.concurrent.ThreadSafe; import javax.annotation.concurrent.ThreadSafe;
import static java.util.Arrays.asList;
import static java.util.Collections.emptyList; import static java.util.Collections.emptyList;
import static java.util.Collections.list; import static java.util.Collections.list;
import static java.util.logging.Level.INFO; import static java.util.logging.Level.INFO;
@@ -206,9 +205,7 @@ abstract class TcpPlugin implements DuplexPlugin, EventListener {
@Override @Override
public void stop() { public void stop() {
for (@Nullable ServerSocket ss : state.setStopped()) { for (ServerSocket ss : state.setStopped()) tryToClose(ss, LOG, WARNING);
tryToClose(ss, LOG, WARNING);
}
} }
@Override @Override
@@ -410,9 +407,7 @@ abstract class TcpPlugin implements DuplexPlugin, EventListener {
State s = getState(); State s = getState();
if (!toClose.isEmpty()) { if (!toClose.isEmpty()) {
LOG.info("Disabled by user, closing server sockets"); LOG.info("Disabled by user, closing server sockets");
for (@Nullable ServerSocket ss : toClose) { for (ServerSocket ss : toClose) tryToClose(ss, LOG, WARNING);
tryToClose(ss, LOG, WARNING);
}
} else if (s == INACTIVE) { } else if (s == INACTIVE) {
LOG.info("Enabled by user, opening server sockets"); LOG.info("Enabled by user, opening server sockets");
bind(); bind();
@@ -445,9 +440,15 @@ abstract class TcpPlugin implements DuplexPlugin, EventListener {
@GuardedBy("this") @GuardedBy("this")
private List<ServerSocket> clearServerSockets() { private List<ServerSocket> clearServerSockets() {
List<ServerSocket> toClose = asList(serverSocketV4, serverSocketV6); List<ServerSocket> toClose = new ArrayList<>(2);
serverSocketV4 = null; if (serverSocketV4 != null) {
serverSocketV6 = null; toClose.add(serverSocketV4);
serverSocketV4 = null;
}
if (serverSocketV6 != null) {
toClose.add(serverSocketV6);
serverSocketV6 = null;
}
return toClose; return toClose;
} }