[ 
https://issues.apache.org/jira/browse/ARTEMIS-3665?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17485263#comment-17485263
 ] 

Stephen Baker commented on ARTEMIS-3665:
----------------------------------------

I can't update artemis on that environment yet; though we will later this year.

I updated the client libraries I was using to 2.20 but it did not change the 
error or the stacktrace.

 

Some time after producing this error I end up with the following log:

{{{}2022-02-01 08:49:25,309 : WARN : Finalizer : client : : AMQ212008: I am 
closing a core ClientSessionFactory you left open. Please make sure you close 
all ClientSessionFactories explicitly before letting them go out of scope! 
600,521,657{}}}{{{}java.lang.Exception: null{}}}{{{}at 
org.apache.activemq.artemis.core.client.impl.ClientSessionFactoryImpl.<init>(ClientSessionFactoryImpl.java:179)
 ~[artemis-core-client-2.17.0.jar:2.17.0]{}}}{{{}at 
org.apache.activemq.artemis.core.client.impl.ServerLocatorImpl.createSessionFactory(ServerLocatorImpl.java:683)
 ~[artemis-core-client-2.17.0.jar:2.17.0]{}}}{{{}at 
com.raveu.msg.sms.broker.server.service.MonitorService.populateJmsQueues(MonitorService.java:196)
 ~[classes/:?]{}}}


The code producing the error is:

{code:java}
@Nullable
private ActiveMQConnectionFactory 
extractInnerArtemisConnectionFactory(JmsTemplate template) {
    ConnectionFactory cf = jmsTemplate.getConnectionFactory();

    if (cf instanceof SingleConnectionFactory) {
        cf = ((SingleConnectionFactory)cf).getTargetConnectionFactory();
    }

    if (cf instanceof ActiveMQConnectionFactory) {
        return (ActiveMQConnectionFactory) cf;
    }
    return null;
}

private void populateJmsQueues(MessagingStatusDTO messagingStatus) {
    if (CollectionUtils.isEmpty(this.jmsQueues)) { return; }

    ActiveMQConnectionFactory cf = 
extractInnerArtemisConnectionFactory(jmsTemplate);
    if (cf == null) {
        messagingStatus.getMonitorErrors()
                .add("JMS Connection Factory is not specified or not Artemis 
ActiveMQConnectionFactory");
        return;
    }

    try (ClientSessionFactory csf = 
cf.getServerLocator().createSessionFactory();
         ClientSession clientSession = createArtemisClientSession(cf, csf);
         ClientRequestor requestor = new ClientRequestor(clientSession, 
"activemq.management")
    ) {
        clientSession.start();

        for (var queue : this.jmsQueues) {
            var status = new QueueStatusDTO();
            status.setName(queue);

            status.setMessages(getJmsManagementValue(
                    clientSession, requestor, "queue." + queue, "messageCount", 
Long.class));
            status.setConsumers(getJmsManagementValue(
                    clientSession, requestor, "queue." + queue, 
"consumerCount", Long.class));

            messagingStatus.getQueueStatuses().add(status);
        }
    } catch (Exception e) {
        messagingStatus.getMonitorErrors().add(ExceptionUtils.getStackTrace(e));
    }
}

private ClientSession createArtemisClientSession(
        ActiveMQConnectionFactory connectionFactory,
        ClientSessionFactory clientSessionFactory) throws ActiveMQException {

    return clientSessionFactory.createSession(
            connectionFactory.getUser(),
            connectionFactory.getPassword(),
            false,
            true,
            true,
            connectionFactory.getServerLocator().isPreAcknowledge(),
            connectionFactory.getServerLocator().getAckBatchSize());
}

private <T> T getJmsManagementValue(
        ClientSession clientSession,
        ClientRequestor requestor,
        String resource,
        String attribute,
        Class<T> clazz) throws Exception {
    ClientMessage m = clientSession.createMessage(false);
    ManagementHelper.putAttribute(m, resource, attribute);
    ClientMessage reply = requestor.request(m);
    return clazz.cast(ManagementHelper.getResult(reply, clazz));
} {code}
 

Due to the try with resources it shouldn't have been possible for the 
ClientSessionFactory to be left open, except that it was never returned due to 
the first NPE.

> NullPointerException in ServerLocator.createSessionFactory
> ----------------------------------------------------------
>
>                 Key: ARTEMIS-3665
>                 URL: https://issues.apache.org/jira/browse/ARTEMIS-3665
>             Project: ActiveMQ Artemis
>          Issue Type: Bug
>          Components: ActiveMQ-Artemis-Native
>    Affects Versions: 2.17.0
>         Environment: Linux version 3.10.0-1160.49.1.el7.x86_64 
> (mockbu...@kbuilder.bsys.centos.org) (gcc version 4.8.5 20150623 (Red Hat 
> 4.8.5-44) (GCC) ) #1 SMP Tue Nov 30 15:51:32 UTC 2021
> Artemis 2.17.0
> Connection string is:
> (tcp://ba-artms21.qa.raveu.net:61616,tcp://ba-artms22.qa.raveu.net:61616)
>            Reporter: Stephen Baker
>            Assignee: Clebert Suconic
>            Priority: Major
>
> In one environment I am frequently seeing a NullPointerException in 
> ServerLocator.createSessionFactory():
> java.lang.NullPointerException
> at 
> org.apache.activemq.artemis.core.client.impl.ClientSessionFactoryImpl.<init>(ClientSessionFactoryImpl.java:189
> at 
> org.apache.activemq.artemis.core.client.impl.ServerLocatorImpl.createSessionFactory(ServerLocatorImpl.java:683)
>  
> The line in the report is:
> `connectorFactory = 
> instantiateConnectorFactory(connectorConfig.getA().getFactoryClassName());`
> Unfortunately I'm not able to reproduce in my development environment which 
> makes debugging difficult.



--
This message was sent by Atlassian Jira
(v8.20.1#820001)

Reply via email to