1 Reply Latest reply on Mar 26, 2015 2:15 PM by jbertram

    HornetQConnectionFactory throws NullPointerException in its finalize method

    stanislav.parkhomenko

      Hi,

       

      I am using hornetq-jms-client 2.4.5.Final library.

      When I instantiate its default constructor

       

      public HornetQConnectionFactory()
      {
        serverLocator = null;
      }
      

       

      the serverLocator attribute is set to null, so when the GC destroys the object in its finalize method

       

      protected void finalize() throws Throwable
      {
         try
         {
            serverLocator.close();
         }
         catch (Exception e)
         {
            e.printStackTrace();
            //not much we can do here
         }
         super.finalize();
      }
      

       

      I'm getting a NullPointerException when serverLocator.close is being invoked.

       

      Is there a way not to avoid this?

       

      Thanks,

      Stas

        • 1. Re: HornetQConnectionFactory throws NullPointerException in its finalize method
          jbertram

          Couple of ideas:

          • Use the org.hornetq.api.jms.HornetQJMSClient.createConnectionFactory* methods to create the connection factory rather than instantiating it directly.  This is the recommended approach to get an instance of org.hornetq.jms.client.HornetQConnectionFactory.
          • Use a different org.hornetq.jms.client.HornetQConnectionFactory constructor.

           

          In any event, you could fix the code and send a PR since you found what appears to be a long-standing bug.