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