Closed dawrut closed 8 years ago
Hi, I've spotted a bug in resolving parameter types. I attached below a snippet with a code that reproduces it. If you run the code, the output is:
K<java.lang.Integer> Ljava/lang/Integer; Ljava/lang/String<Ljava/lang/Integer;>; Ljava/util/List<Ljava/lang/Integer;>; Ljava/util/Map<Ljava/lang/String;LClazz;>;
which is not correct.
The ' Ljava/lang/String<Ljava/lang/Integer;>;' is wrong since String is not parametrised.
As I can see, TypeResolver#_constructType calls for:
return new ResolvedObjectType(rawType, typeBindings, _resolveSuperClass(context, rawType, typeBindings), _resolveSuperInterfaces(context, rawType, typeBindings));
where super constructor is called:
protected ResolvedType(Class<?> cls, TypeBindings bindings) { _erasedType = cls; _typeBindings = (bindings == null) ? TypeBindings.emptyBindings() : bindings; }
but there is no check whether the type is parametrised or so. Version: 1.1.0
Many thanks
The snippet:
import com.fasterxml.classmate.MemberResolver; import com.fasterxml.classmate.ResolvedType; import com.fasterxml.classmate.ResolvedTypeWithMembers; import com.fasterxml.classmate.TypeResolver; import com.fasterxml.classmate.members.ResolvedMethod; import java.util.List; import java.util.Map; public class Clazz<T extends Number> { public void method(K<T> arg0) { } } class K<Z> { public void method(Z arg0, String arg1, List<Z> arg2, Map<String, Clazz<Integer>> arg3) { } } class Main { public static void main(String[] args) { TypeResolver typeResolver = new TypeResolver(); ResolvedType resolvedClazz = typeResolver.resolve(Clazz.class, Integer.class); MemberResolver clazzMemberResolver = new MemberResolver(typeResolver); ResolvedTypeWithMembers resolvedClazzMembersTypes = clazzMemberResolver.resolve(resolvedClazz, null, null); for (ResolvedMethod resolvedClazzMethod : resolvedClazzMembersTypes.getMemberMethods()) { for (int i = 0; i < resolvedClazzMethod.getArgumentCount(); i++) { ResolvedType type = resolvedClazzMethod.getArgumentType(i); System.out.println(type); ResolvedTypeWithMembers kMembers = clazzMemberResolver.resolve(type, null, null); for (ResolvedMethod kMethod : kMembers.getMemberMethods()) { for (int j = 0; j < kMethod.getArgumentCount(); j++) { System.out.print(kMethod.getArgumentType(j).getSignature() + " "); } } } } } }
Thank you for reporting this. I will have a look, and try to fix it.
Now that #28 is fixed (in 1.3.0), I suspect this may also have been resolved.
Hi, I've spotted a bug in resolving parameter types. I attached below a snippet with a code that reproduces it. If you run the code, the output is:
which is not correct.
The ' Ljava/lang/String<Ljava/lang/Integer;>;' is wrong since String is not parametrised.
As I can see, TypeResolver#_constructType calls for:
where super constructor is called:
but there is no check whether the type is parametrised or so. Version: 1.1.0
Many thanks
The snippet: