Freitag, 16. September 2011

Weld SE - Strange Exception (ArrayIndexOutOfBoundException : 3)

Trying to integrate WELD-SE to your project my fail with such exceptions. Weld has a bug in the implementation and if you don't want to wait for a fix, use the solution described as below.

Cause:
The main problem was the class WeldConsturctorImpl at line 113 :

if (constructor.getParameterAnnotations()[i].length > 0)







WELD doesn't check whether the returned array has valid length, because the condition for i is not depends on getParameterAnnotations() :

for (int i = 0; i < constructor.getParameterTypes().lengthi++)

This error occurs while WELD scans the annotation of all constructors on class path and this exception occurs while checking the constructor of AbstractMultimap$WrappedCollection class.

Solution:
You need to exclude this package, just write this exclusion to beans.xml : 

 <weld:scan>
        <weld:exclude name="com.google.common.collect.*"/>
 </weld:scan>

It is also a best practise to exclude everything outside of your package, so WELD won't scan them and start-up performance will be much better!