Issue Details (XML | Word | Printable)

Key: NUCENHANCER-84
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Unassigned
Reporter: Ray Hu
Votes: 0
Watchers: 0
Operations

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 test.zip (3 kB)

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

Forum Thread URL: http://www.datanucleus.org/servlet/forum/viewthread_thread,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{
}

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(ClassUtils.java:1436)
at org.datanucleus.api.jdo.metadata.JDOAnnotationReader.processMemberAnnotations(JDOAnnotationReader.java:1652)
...

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);
           }

Ray Hu made changes - 06/Jun/12 06:08 AM
Field Original Value New Value
Attachment test.zip [ 11661 ]
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.

Andy Jefferson made changes - 06/Jul/12 09:42 AM
Status Open [ 1 ] Resolved [ 5 ]
Fix Version/s 3.1.0.m1 [ 11553 ]
Resolution Fixed [ 1 ]
Andy Jefferson made changes - 06/Jul/12 09:43 AM
Status Resolved [ 5 ] Closed [ 6 ]