damonkohler / rosjava

Automatically exported from code.google.com/p/rosjava
0 stars 0 forks source link

NullPointerException in logger when called before first clock message #148

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Start a roscore with param use_sim_time=true, but don't publish /clock yet 
(i.e., no rosbag play, no gazebo)
2. Create a new node that does something in onStart() which will directly or 
indirectly trigger connectedNode.getCurrentTime(), such as 
connectedNode.getLog().fatal(e)

What is the expected output? What do you see instead?

Exception in thread "pool-1-thread-3" java.lang.NullPointerException
    at com.google.common.base.Preconditions.checkNotNull(Preconditions.java:191)
    at org.ros.time.ClockTopicTimeProvider.getCurrentTime(ClockTopicTimeProvider.java:60)
    at org.ros.internal.node.DefaultNode.getCurrentTime(DefaultNode.java:377)
    at org.ros.internal.node.RosoutLogger.publish(RosoutLogger.java:58)
    at org.ros.internal.node.RosoutLogger.fatal(RosoutLogger.java:182)
    at race_sam_reasoner.RaceSamNode.onStart(RaceSamNode.java:127)
    at org.ros.internal.node.DefaultNode$5.run(DefaultNode.java:506)
    at org.ros.internal.node.DefaultNode$5.run(DefaultNode.java:503)
    at org.ros.concurrent.EventDispatcher.loop(EventDispatcher.java:43)
    at org.ros.concurrent.CancellableLoop.run(CancellableLoop.java:56)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
    at java.lang.Thread.run(Thread.java:679)

What version of the product are you using? On what operating system?

rosjava -r 1096:c655a7f4f79a, Ubuntu Oneiric 11.10, ROS fuerte

Please provide any additional information below.

Original issue reported on code.google.com by martin.g...@gmail.com on 28 Oct 2012 at 1:26

GoogleCodeExporter commented 9 years ago
For an ugly workaround, add the following as the first lines of onStart():

// wait until we have a clock signal
while (true) {
    try {
        connectedNode.getCurrentTime();
        break; // no exception, so let's stop waiting
    } catch (NullPointerException e) {
        try {
            Thread.sleep(100);
        } catch (InterruptedException e1) {
        }
    }
}

Original comment by martin.g...@gmail.com on 28 Oct 2012 at 1:31