A NullPointer

Well if you have been on my twitter stream, you would know that i had an issue with a NullPointerException getting thrown in a Java program.

The program was part of a quick and dirty proof-of-technology or PoT. The aim here was to have a program listen to the events from a broker and based on the events the program was required to get the details from the broker environment. The events that were of interest to me where create, update and delete.

The standalone program was structured like this:

The initialize() function returns a broker connection object and is used by the retrieveDetails() function to get the details from the broker.

The program worked perfectly for update and delete events. But when the create event was triggered the broker object was unable to get the details. It always returned null thus throwing the NullPointerException.

Well the solution to this was to create a new broker object within the retrieveDetails() function if the event is create. And it worked.

I have no idea why it didn’t work the way it was designed initially. It might be because the broker object was already created before the create event. But that could not be the reason as the broker object is only used to retrieve the details about the flow from the deployed broker and doesn’t really hold any information. It is similar to the database connection object which is used to query the details from the database.

  • http://twitter.com/tweetanaram Anand Ramachandran

    What information was being returned by the retrieveDetails() function?

    • http://twitter.com/jerrymannel Jerry Mannel

      It displays the details about the flow like flow name, nodes with-in the flow, information on each node etc etc..

      • http://twitter.com/tweetanaram Anand Ramachandran

        Y dont u try figuring out with a DFD? I guess your retrieveDetails() function is seeking details before an object is being created..

        Excuse me for being so lame.. But in the absence of the code, I can only make some suggestions.. :)

        I repeat – Use DFD!!

        • http://twitter.com/jerrymannel Jerry Mannel

          i don’t think that the function is asking for details before the object is created. The events get generated after the objects are successfully created in the broker. Then why is it working for update?

          There is no DFD, it’s a PoC/PoT all that mattered at the end was a successful demo. :)