NoClassDefFound test error with Jacoco

  • Vincent Massol
    Vincent Massol

    Hi guys,

    I'm trying out Jacoco on some maven project. This project builds fine when I don't have Jacoco in the project but as soon as I have it my tests fail with on some third party dep I'm using (PircBotX):

    Caused by: java.lang.ArrayIndexOutOfBoundsException: 0
            at org.pircbotx.hooks.ListenerAdapter.<clinit>(

    I've checked the source code and line 106 is:

    Class<?> curClass = curMethod.getParameterTypes();


    static {
    //Map events to methods
    for (Method curMethod : ListenerAdapter.class.getDeclaredMethods()) {
    if (curMethod.getName().equals("onEvent"))
    Class<?> curClass = curMethod.getParameterTypes();
    if (!curClass.isInterface()) {
    Set methods = new HashSet();
    eventToMethod.put((Class<? extends Event>) curClass, methods);

    So it seems Jacoco's instrumentation is messing something up but since I don't know what code Jacoco injects I have no clue what the problem can be.

    Any idea?

    Thanks a lot

  • Vincent Massol
    Vincent Massol

    Note: Sorry about the title of this issue. I thought the problem was a NoClassDefFoundError initially but I think the root cause is instead this ArrayIndexOutOfBoundsException I reported above.

  • Vincent Massol
    Vincent Massol

    ok found the problem I think. I was able to see that the method that generates the problem is:

    private static final boolean org.pircbotx.hooks.ListenerAdapter.$jacocoInit()

    So the issue is that the PircBotX project has some code that is not well protected against problems…

    I'll read up to find a way to exclude this class from instrumentation

  • Vincent Massol
    Vincent Massol

    ok I found it and it works :)

    For the record:


  • Your analysis is correct. JaCoCo adds two members to instrumented classes:

    - static field $jacocoData
    - static method $jacocoInit

    Both members have the modifiers private and synthetic. So frameworks really shouldn't touch such members.