#2 Nullpointer exceptin when closing timer

open
nobody
None
5
2006-08-24
2006-08-24
Anonymous
No

Sometimes when the SnmpSession.close() is called in
version 0.3.4 a nullpointer exception is thrown in
TimerLogic.cancel() at

m_thread.interrupt();

(m_thread is null)

This is probably due to the TimerLogic having
m_isActive = true even when the run method (which
sets m_thread to current thread) has not been called.

This does not happen when the same code is run in
0.3.2.

I suggest the TimerLogic.cancel(boolean) is changed
to :

public synchronized void cancel(boolean waitForAll)
{
if (m_isActive)
{
m_isActive = false;

if (m_thread != null) {
m_thread.interrupt();
}
}

if (waitForAll)
{
while (true)
{
try
{
if (m_thread != null) {
m_thread.join();
}
break;
}
catch (InterruptedException e)
{
// ignore
}
}
}
}

Best regards,

/Erik

erik.halen@andrew.com

Discussion

  • Nobody/Anonymous

    Suggested fix

     
  • AdamWozPL

    AdamWozPL - 2009-06-22

    Hello

    Yep.
    I would like to confirm, that I have the same problem.

    The exception is:
    Exception in thread "main" java.lang.NullPointerException
    at org.opennms.protocols.snmp.SnmpTimer$TimerLogic.cancel(SnmpTimer.java:177)
    at org.opennms.protocols.snmp.SnmpTimer.cancel(SnmpTimer.java:80)
    at org.opennms.protocols.snmp.SnmpSession.close(SnmpSession.java:961)
    ....

    I think, that it is quite simple to reproduce:
    1. take an example: joesnmp-0.3.4\src\joesnmp\org\opennms\examples\SimpleClient.java
    2. Rename main to main2.
    3. Add new main method:
    public static void main(String[] args) throws Exception
    {
    for(int i = 0; i < 10; i++)
    main2(args);
    }

    In my environment it's crashing every time i run it.

    Regards,
    Adam

     
  • Jakub Neubauer

    Jakub Neubauer - 2010-01-26

    The suggested patch is not good, it doesn's solve the reason why the m_thread is null and only checks for it. I think that the right fix is in the patch provided for the bug 2829316 "deadlock when closing SnmpSession".