[jboss-dev] inner classes and param types
Ales Justin
ales.justin at gmail.com
Fri Mar 2 11:10:46 EST 2012
Anyone seen this, or how to make this deterministic ...
I have these 2 classes - (a) and (b) - see below.
And this code:
final Annotation[][] parameterAnnotations = constructor.getParameterAnnotations();
final Type[] genericParameterTypes = constructor.getGenericParameterTypes();
// If the class is a (non-static) member class, its constructors
// parameterTypes array will prefix the
// outer class instance, whilst the genericParameterTypes array isn't
// prefix'd -- not always true ...
int nesting = Reflections.getNesting(declaringClass.getJavaClass());
for (int i = 0; i < parameterTypes.length; i++) {
int gi = i - nesting;
Annotation[] annotations = (gi >= 0 && parameterAnnotations[gi].length > 0) ? parameterAnnotations[gi] : EMPTY;
Class<?> clazz = parameterTypes[i];
Type parameterType = genericParameterTypes[i];
So, the issue is - as I added "not always true" to the existing comment,
that "genericParameterTypes" are random in my case --
sometimes they have owner class prefixed == use case (a),
sometimes they don't == use case (b), hence resulting in ArrayIOOBE.
Any idea why is this so?
-Ales
---
(a)
public class Crasher {
protected class NonStaticInner {
public NonStaticInner(@Nonnull Integer a) {
System.out.println("Hi" + a);
}
protected class NonStaticInner2 {
public NonStaticInner2(@Nonnull Double a) {
System.out.println("Hi" + a);
}
}
}
}
(b)
public class ExampleTest {
...
public class NonContextual<T> {
final InjectionTarget<T> it;
final BeanManager manager;
public NonContextual(BeanManager manager, Class<T> clazz) {
this.manager = manager;
AnnotatedType<T> type = manager.createAnnotatedType(clazz);
this.it = manager.createInjectionTarget(type);
}
public CreationalContext<T> postConstruct(T instance) {
CreationalContext<T> cc = manager.createCreationalContext(null);
it.inject(instance, cc);
it.postConstruct(instance);
return cc;
}
public void preDestroy(T instance) {
it.preDestroy(instance);
}
}
}
More information about the jboss-development
mailing list