[jboss-dev] generic collection item type
Adrian
abrock at redhat.com
Thu Aug 2 10:26:07 EDT 2007
I've applied your patch, but I don't understand why the NPE happens?
Why wouldn't a class implement its interface?
Basically I want to write a test for what you were seeing.
ClassInfo info = ...;
info.getComponentType(); // Should not throw NPE! :-)
On Wed, 2007-08-01 at 11:03 +0200, Alexey Loubyansky wrote:
> Yes, it does work! Thanks!
>
> I had to add a check that the interface implements the reference before
> calling locateActualType because in case of Comparable<T> and so on I
> would get NPE later. I checked out the trunk but it didn't build. So,
> here is the diff.
>
> Type[] interfaces = clazz.getGenericInterfaces();
> for (Type intf : interfaces)
> - {
> - Type result;
> + {
> + Class interfaceClass;
> if (intf instanceof Class)
> {
> - Class interfaceClass = (Class) intf;
> - result = locateActualType(reference, parameter,
> interfaceClass, intf);
> - if (result instanceof TypeVariable)
> - result = getParameter(clazz, type, (TypeVariable) result);
> + interfaceClass = (Class) intf;
> }
> else if (intf instanceof ParameterizedType)
> {
> ParameterizedType interfaceType = (ParameterizedType) intf;
> - Class interfaceClass = (Class) interfaceType.getRawType();
> + interfaceClass = (Class) interfaceType.getRawType();
> + }
> + else
> + throw new IllegalStateException("Unexpected type " +
> intf.getClass());
> +
> + Type result = null;
> + if (reference.isAssignableFrom(interfaceClass))
> + {
> result = locateActualType(reference, parameter,
> interfaceClass, intf);
> if (result instanceof TypeVariable)
> result = getParameter(clazz, type, (TypeVariable) result);
> }
> - else
> - throw new IllegalStateException("Unexpected type " +
> intf.getClass());
> +
> if (result != null)
> return result;
--
xxxxxxxxxxxxxxxxxxxxxxxxxxxx
Adrian Brock
Chief Scientist
JBoss, a division of Red Hat
xxxxxxxxxxxxxxxxxxxxxxxxxxxx
More information about the jboss-development
mailing list