Issue Details (XML | Word | Printable)

Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Unassigned
Reporter: Ray Hu
Votes: 0
Watchers: 0

If you were logged in you would be able to see more operations.
DataNucleus Enhancer (ARCHIVED)

Enhancer 3.0 failed on collection with generics which worked in 2.2

Created: 06/Jun/12 06:07 AM   Updated: 06/Jul/12 09:43 AM   Resolved: 06/Jul/12 09:42 AM
Component/s: None
Affects Version/s: 3.0.0.m1, 3.0.0.m2, 3.0.0.m3, 3.0.0.m4, 3.0.0.m5, 3.0.0.m6, 3.0.0.release, 3.0.1
Fix Version/s: 3.1.0.m1

File Attachments: 1. Zip Archive (3 kB)

Environment: Win7(64bit) + Eclipse + JRE 1.6

Forum Thread URL:,6807
Severity: Production

 Description  « Hide
Following classes used to be working fine under datanucleus 2.X,but since 3.X enhancer complain
that "Unsupported generic type: T"

public class A<T extends B > {
        List<T> bList;
public class B {
        String name;
public class C extends B{

Sort Order: Ascending order - Click to sort in descending order
Ray Hu added a comment - 06/Jun/12 06:08 AM - edited
By tracking exception :
org.datanucleus.exceptions.NucleusUserException: Unsupported generic type: T
at org.datanucleus.util.ClassUtils.getCollectionElementType(
at org.datanucleus.api.jdo.metadata.JDOAnnotationReader.processMemberAnnotations(

In ClassUtils.getCollectionElementType(Class type,Type genericType)
where if genericType is instance of ParameterizedType,then the first actual type argument (argType) will check the supported type.Unfortunately TypeVariable is not one of the supported Type(Only Class,ParameterizedType and GenericArrayType was supported).
Is this something related to type erasing ?
But if generic(T) extends some concrete class and has only one parameter as the example above this info can somehow be retrieved from defined class but need to change the signature of method a bit.

line 1487 if (argType instanceof Class)
          else if (argType instanceof ParameterizedType)
          else if (argType instanceof GenericArrayType)
          else if (argType instanceof TypeVariable)

            // declaringClass came from method parameters
            TypeVariable[] tvs = declaringClass.getTypeParameters();
        if(tvs.length == 1)
              Type[] bounds = tvs[0].getBounds();
              if(bounds.length == 1 && bounds[0] instanceof Class)
         return (Class)bounds[0];
            throw new RuntimeException("Unsupported generic type : " + argType);

Andy Jefferson added a comment - 06/Jul/12 09:42 AM
Unreproduceable with SVN code. That code snippet posted doesn't compile; a patch is the way of contributing updates.