This is an automated email from the ASF dual-hosted git repository.
jbertram pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/artemis.git
The following commit(s) were added to refs/heads/main by this push:
new d4e4ff20d8 ARTEMIS-5986 NPE when starting broker w/o Hawtio
new 64ed9a303b This closes #6337
d4e4ff20d8 is described below
commit d4e4ff20d853008f376998a2c478cfe7db30581d
Author: Emmanuel Hugonnet <[email protected]>
AuthorDate: Thu Apr 2 14:43:35 2026 +0200
ARTEMIS-5986 NPE when starting broker w/o Hawtio
Signed-off-by: Emmanuel Hugonnet <[email protected]>
---
.../management/impl/ManagementServiceImpl.java | 2 +-
.../management/impl/ManagementServiceImplTest.java | 43 ++++++++++++++++++++++
2 files changed, 44 insertions(+), 1 deletion(-)
diff --git
a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/management/impl/ManagementServiceImpl.java
b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/management/impl/ManagementServiceImpl.java
index bb35f814c6..fbc00f0ca0 100644
---
a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/management/impl/ManagementServiceImpl.java
+++
b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/management/impl/ManagementServiceImpl.java
@@ -783,7 +783,7 @@ public class ManagementServiceImpl implements
ManagementService {
getResources(resourceType, getClusterConnectionControls(), resources);
getResources(resourceType, getConnectionRouterControls(), resources);
getResources(resourceType, getDivertControls(), resources);
- if (resourceType.isAssignableFrom(getHawtioSecurity().getClass())) {
+ if (getHawtioSecurity() != null &&
resourceType.isAssignableFrom(getHawtioSecurity().getClass())) {
resources.add(getHawtioSecurity());
}
resources.addAll(getUntypedControls(resourceType));
diff --git
a/artemis-server/src/test/java/org/apache/activemq/artemis/core/server/management/impl/ManagementServiceImplTest.java
b/artemis-server/src/test/java/org/apache/activemq/artemis/core/server/management/impl/ManagementServiceImplTest.java
index 38ddebbc85..c39ea9a037 100644
---
a/artemis-server/src/test/java/org/apache/activemq/artemis/core/server/management/impl/ManagementServiceImplTest.java
+++
b/artemis-server/src/test/java/org/apache/activemq/artemis/core/server/management/impl/ManagementServiceImplTest.java
@@ -35,12 +35,16 @@ import
org.apache.activemq.artemis.core.security.SecurityStore;
import org.apache.activemq.artemis.core.server.ActiveMQServer;
import org.apache.activemq.artemis.core.server.Queue;
import org.apache.activemq.artemis.core.server.impl.AddressInfo;
+import
org.apache.activemq.artemis.core.server.management.GuardInvocationHandler;
+import
org.apache.activemq.artemis.core.server.management.HawtioSecurityControl;
import org.apache.activemq.artemis.spi.core.remoting.Acceptor;
import org.apache.activemq.artemis.utils.ExecutorFactory;
import org.apache.activemq.artemis.utils.actors.ArtemisExecutor;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
@@ -235,4 +239,43 @@ public class ManagementServiceImplTest {
Mockito.verifyNoInteractions(securityStore);
}
+
+ @Test
+ public void testGetResourcesWithNullHawtioSecurity() throws Exception {
+ Configuration configuration = new FileConfiguration();
+ ManagementServiceImpl managementService = new
ManagementServiceImpl(mBeanServer, configuration);
+
+ Mockito.when(executorFactory.getExecutor()).thenReturn(artemisExecutor);
+
Mockito.when(messagingServer.getExecutorFactory()).thenReturn(executorFactory);
+
Mockito.when(messagingServer.getManagementService()).thenReturn(managementService);
+ Mockito.when(postOffice.isStarted()).thenReturn(true);
+ Mockito.when(messagingServer.getPostOffice()).thenReturn(postOffice);
+
+ managementService.registerServer(null, securityStore, null,
configuration, null, null, null, null, messagingServer, null, null, null,
false);
+
+ // HawtioSecurity is not registered - getResources must not throw NPE
+ Object[] resources =
managementService.getResources(HawtioSecurityControl.class);
+ assertEquals(0, resources.length);
+ }
+
+ @Test
+ public void testGetResourcesWithHawtioSecurity() throws Exception {
+ Configuration configuration = new FileConfiguration();
+ ManagementServiceImpl managementService = new
ManagementServiceImpl(mBeanServer, configuration);
+
+ Mockito.when(executorFactory.getExecutor()).thenReturn(artemisExecutor);
+
Mockito.when(messagingServer.getExecutorFactory()).thenReturn(executorFactory);
+
Mockito.when(messagingServer.getManagementService()).thenReturn(managementService);
+ Mockito.when(postOffice.isStarted()).thenReturn(true);
+ Mockito.when(messagingServer.getPostOffice()).thenReturn(postOffice);
+
+ managementService.registerServer(null, securityStore, null,
configuration, null, null, null, null, messagingServer, null, null, null,
false);
+
+ GuardInvocationHandler guard =
Mockito.mock(GuardInvocationHandler.class);
+ managementService.registerHawtioSecurity(guard);
+
+ Object[] resources =
managementService.getResources(HawtioSecurityControl.class);
+ assertEquals(1, resources.length);
+ assertInstanceOf(HawtioSecurityControl.class, resources[0]);
+ }
}
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]