I have been using OJB with JBOSS/TOMCAT, and finding that it would crash every now and
then. I debugged the code to find it was crashing in the following methods of
org.apache.ojb.broker.PersistenceBrokerFactory class:
setCurrentPersistenceBroker()
currentPersistenceBroker()
I found that in both these methods the following statement:
HashMap map = (HashMap) currentBrokerMap.get();
would return a null map object every now and then, and since the code does not check
for the null map object it would crash on those occasions.
I added the following fix:
HashMap map = (HashMap) currentBrokerMap.get();
if (null == map)
{
currentBrokerMap.set(new HashMap());
map = (HashMap) currentBrokerMap.get();
}
if (null != map)
{
....
}
This seems to have solved my problem, but I am not quite sure why the map object is
(occasionally) null when it is being initialized in static statement of the class.
Any ideas?