Menu

#79 Cobertura fails with JUnit tests that uses multiple threads

closed-fixed
None
5
2009-06-25
2009-05-15
Anonymous
No

A JUnit test with a number of threads which makes calls to the same class (not necessaries the same object) will fail with Cobertura because of a bug in Cobertura. The problem is that the classes inside Cobertura's coveragedata package is not thread safe and when collecting data from concurrent threads this can result in an exception which look something like:

java.lang.IndexOutOfBoundsException: Index: 0, Size: 1
at java.util.ArrayList.RangeCheck(ArrayList.java:547)
at java.util.ArrayList.get(ArrayList.java:322)
at net.sourceforge.cobertura.coveragedata.LineData.getJumpData(LineData.java:316)
at net.sourceforge.cobertura.coveragedata.LineData.touchJump(LineData.java:259)
at net.sourceforge.cobertura.coveragedata.ClassData.touchJump(ClassData.java:453)
at code.ConcurrentAccessObject.addText(ConcurrentAccessObject.java:25)
at test.ConcurrentAccessObjectTest$TestThread.run(ConcurrentAccessObjectTest.java:30)

I have written a fix for the bug which makes the touch methods on the ClassData class synchronized. This does that only one thread is allowed to update the coveragedata when running tests.

Please note that the bug is not easy to reproduce consistently because it is a concurrency bug. The included JUnit test case will therefore not always work.
Also note that is fixes the same problem as Cobertura patch 2722288 in SourceForge. But I think that my patch may be a simpler and better solution.

Discussion

  • Nobody/Anonymous

    Patch for ClassData and JUnit test case to produce the error

     
  • John Lewis

    John Lewis - 2009-06-25

    Thanks for the patch, but I cannot open it for some reason. Is it corrupt?

    This issue has recently been fixed. I hope to release 1.9.2 today. It will have the fix.

     
  • John Lewis

    John Lewis - 2009-06-25
    • assigned_to: nobody --> lewijw
    • status: open --> closed-fixed
     
  • Nobody/Anonymous

    Greetings from California! I'm bored to death at work so I decided to browse your website on my iphone during lunch break. I enjoy the information you present here and can't wait to take a look when I get home. I'm amazed at how fast your blog loaded on my cell phone .. I'm not even using WIFI, just 3G .. Anyways, great blog!
    north face jackets clearance http://yuywfrbgzf.blogoak.com/

     
  • Nobody/Anonymous

    I was curious if you ever thought of changing the structure of your blog? Its very well written; I love what youve got to say. But maybe you could a little more in the way of content so people could connect with it better. Youve got an awful lot of text for only having 1 or two images. Maybe you could space it out better?
    north face osito jacket http://sfwgdqdfge.blinkweb.com/

     
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.