Skip to content

Commit

Permalink
Avoid NPE if broker yet not started (#743)
Browse files Browse the repository at this point in the history
Update Server's listConnectedClients to check that the server instance is initialized, to avoid NPE. If not throws an state exception.

---------

Co-authored-by: Andrea Selva <selva.andre@gmail.com>
  • Loading branch information
source-c and andsel committed May 6, 2023
1 parent f306b6c commit e189866
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions broker/src/main/java/io/moquette/broker/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -634,8 +634,13 @@ public void removeInterceptHandler(InterceptHandler interceptHandler) {

/**
* Return a list of descriptors of connected clients.
* Returns null if the broker is not started.
* */
public Collection<ClientDescriptor> listConnectedClients() {
if (!initialized) {
LOG.error("Moquette is not started, MQTT clients listing unavailable");
throw new IllegalStateException("Can't get clients list from a Server that is not yet started");
}
return sessions.listConnectedClients();
}
}

0 comments on commit e189866

Please sign in to comment.