ilikecats567 / arduino

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

Avoid null pointer exception during compilation (by making local copy of thread object) #950

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1.  compile the code -- VERY difficult to reproduce but somehow seems to get me 
20x per day

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

java.lang.NullPointerException
    at processing.app.debug.Compiler.execAsynchronously(Compiler.java:407)
    at processing.app.debug.Compiler.compile(Compiler.java:187)
    at processing.app.Sketch.build(Sketch.java:1590)
    at processing.app.Sketch.build(Sketch.java:1567)
    at processing.app.Editor$DefaultRunHandler.run(Editor.java:1863)
    at java.lang.Thread.run(Thread.java:679)

What version of the Arduino software are you using? On what operating
system?  Which Arduino board are you using?

latest github, Mint 12, does not matter.

Please provide any additional information below.

The problem is a race condition between the check in this code AND the join.  
That is, if in/err.thread becomes null at the starred moments you'll get the 
exception

-        if (in.thread != null)  
           /* *** */
-          in.thread.join();
-        if (err.thread != null)
           /* *** */
-          err.thread.join();

This happens because the in and err objects are MessageSiphons which set its  
.thread member variable to null when it is done (see MessageSiphon.java:run).

The fix is to simply only grab the thread object once from each MessageSiphon:

        Thread t = in.thread;
        if (t != null)
          t.join();
        t = err.thread;
        if (t != null)
          t.join();

I will regress for a few days before I submit a pull req.

Original issue reported on code.google.com by G.Andrew...@gmail.com on 6 Jun 2012 at 9:29

GoogleCodeExporter commented 9 years ago
https://github.com/arduino/Arduino/commit/6d6f4424e41fe1f6b68da0e1f409a44aae7669
be

Original comment by dmel...@gmail.com on 11 Jun 2012 at 1:37