karouani / javasimon

Automatically exported from code.google.com/p/javasimon
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

NPE in TimelineCallback #113

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago

A NullPointerException occurred in an application that was running for several 
weeks with no problems:

Caused by: java.lang.NullPointerException: null
        at org.javasimon.callback.timeline.TimelineCallback.onStopwatchStop(TimelineCallback.java:112) ~[javasimon-core-3.3.0.jar:na]
        at org.javasimon.callback.CompositeCallbackImpl.onStopwatchStop(CompositeCallbackImpl.java:146) ~[javasimon-core-3.3.0.jar:na]
        at org.javasimon.StopwatchImpl.stop(StopwatchImpl.java:125) ~[javasimon-core-3.3.0.jar:na]
        at org.javasimon.Split.stop(Split.java:95) ~[javasimon-core-3.3.0.jar:na]
        at org.javasimon.jdbc4.SimonResultSet.next(SimonResultSet.java:62) ~[javasimon-jdbc4-3.3.0.jar:na]
        at org.springframework.jdbc.core.RowMapperResultSetExtractor.extractData(RowMapperResultSetExtractor.java:91) ~[spring-jdbc-3.2.3.RELEASE.jar:3.2.3.RELEASE]
        at org.springframework.jdbc.core.RowMapperResultSetExtractor.extractData(RowMapperResultSetExtractor.java:60) ~[spring-jdbc-3.2.3.RELEASE.jar:3.2.3.RELEASE]
        at org.springframework.jdbc.core.JdbcTemplate$1.doInPreparedStatement(JdbcTemplate.java:651) ~[spring-jdbc-3.2.3.RELEASE.jar:3.2.3.RELEASE]
        at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:589) ~[spring-jdbc-3.2.3.RELEASE.jar:3.2.3.RELEASE]
        at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:639) ~[spring-jdbc-3.2.3.RELEASE.jar:3.2.3.RELEASE]
        at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:664) ~[spring-jdbc-3.2.3.RELEASE.jar:3.2.3.RELEASE]
        at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:704) ~[spring-jdbc-3.2.3.RELEASE.jar:3.2.3.RELEASE]
        at org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate.queryForObject(NamedParameterJdbcTemplate.java:195) ~[spring-jdbc-3.2.3.RELEASE.jar:3.2.3.RELEASE]
        at org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate.queryForObject(NamedParameterJdbcTemplate.java:202) ~[spring-jdbc-3.2.3.RELEASE.jar:3.2.3.RELEASE]
        at org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate.queryForObject(NamedParameterJdbcTemplate.java:214) ~[spring-jdbc-3.2.3.RELEASE.jar:3.2.3.RELEASE]

Environment: JavaSimon 3.3.0, WebSphere 7, DB2 9.7, SuseLinux x64

Do you know what could be the cause?

Original issue reported on code.google.com by z...@summa.com.br on 25 Oct 2013 at 6:29

GoogleCodeExporter commented 8 years ago
Looking at the line - two things might have happened:
- either the split didn't have a Stopwatch - while it is possible (anonymous 
Split created directly), this method is called for Split's stopwatch (and 
actually from stopwatch code), so we can rule this out
- or no timeline was found... which seems the probable cause

I can't say for sure what could be the reason. 
org.javasimon.callback.timeline.TimelineCallback#onSimonCreated is called in 
synchronized section on Manager and there should be no way how stopwatch 
without the timeline gets out of this call. What could happen is that there 
were some stopwatches already before the callback. These could be initialized 
in the Callback's initialize() - however this does not get manager as a 
parameter, so it should not use it (or we should introduce this feature).

This leads to lazy init the timeline attribute for the stopwatch if it does not 
exist yet - or ignoring the event if the timeline is null. Right now I'll 
commit those checks (ifs) and later we can investigate this a bit more.

Original comment by virgo47 on 3 Nov 2013 at 10:27

GoogleCodeExporter commented 8 years ago
Fixed by http://code.google.com/p/javasimon/source/detail?r=1599a57f8eb0 - 
added test as well.

Original comment by virgo47 on 3 Nov 2013 at 11:43

GoogleCodeExporter commented 8 years ago
We implemented a method to reset all Simons, maybe it was used in that exact 
time leading to a concurrency problem.

    public void reset(String simonName) {
        if (SimonManager.getSimon(simonName) == null) {
            throw new IllegalArgumentException(String.format("Simon '%s' not found", simonName));
        }
        reset(SimonManager.getSimon(simonName));
    }

    private void reset(Simon simon) {
        simon.reset();
        for (Simon childSimon : simon.getChildren()) {
            reset(childSimon);
        }
    }

Is it the recommended way to achieve this?

Thanks for looking after this issue.

Original comment by z...@summa.com.br on 4 Nov 2013 at 4:46

GoogleCodeExporter commented 8 years ago
Hi Ziba - your first method is ok, the second one is actually just a copy of 
our org.javasimon.utils.SimonUtils#recursiveReset, so you can call that one 
directly from the first one. Reset however does not affect attributes, so it 
should not be a problem.

The only way I see now is that your app somehow accessed some stopwatch created 
before the timeline callback was added. I'm not saying that's what happened, I 
just don't see other way now. NPE was in any case too harsh, now worst can 
happen is that you have some stopwatch without a timeline.

Original comment by virgo47 on 4 Nov 2013 at 8:17