devBuzzy / pircbotx

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

Bug in ListenerAdapter static code #66

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
The code with the problem is:

        for (Method curMethod : ListenerAdapter.class.getDeclaredMethods()) {
            if (curMethod.getName().equals("onEvent"))
                continue;
            Class<?> curClass = curMethod.getParameterTypes()[0];

If it happens that your listener has a method for which getParameterTypes() 
returns an empty array then you'll get:

Caused by: java.lang.ArrayIndexOutOfBoundsException: 0

This problem happens for example when I use Jacoco on my XWiki code as it tries 
to instrument ListenerAdapter and fail at runtime on a method like this:

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

See 
https://sourceforge.net/projects/eclemma/forums/forum/614870/topic/5108076/index
/page/1 for details.

The solution is to add a check.

Original issue reported on code.google.com by vmas...@gmail.com on 11 Mar 2012 at 1:54

GoogleCodeExporter commented 9 years ago
Hmm, I didn't foresee anyone compiling PircBotX with strange preprocessors that 
would add random methods to the ListenerAdapter class.

I'll add checks and keep conformance to the correct method signatures in unit 
tests.

Thanks for pointing that out

Original comment by Lord.Qua...@gmail.com on 11 Mar 2012 at 5:03

GoogleCodeExporter commented 9 years ago
Fixed in Revision b4bd61b732a0

Original comment by Lord.Qua...@gmail.com on 17 Mar 2012 at 1:33