podam
podam copied to clipboard
Podam doesn't handle whildcard generics with JDK1.7
import java.util.List;
import uk.co.jemos.podam.api.PodamFactory; import uk.co.jemos.podam.api.PodamFactoryImpl;
public class PodamTest {
public class Pojo {
private List<? extends Object> objs;
public List<? extends Object> getObjs() {
return objs;
}
public void setObjs(List<? extends Object> objs) {
this.objs = objs;
}
@Override
public String toString() {
return "{objs: '" + objs + "'}";
}
}
public static void main(String[] args) {
PodamFactory factory = new PodamFactoryImpl();
Pojo pojo = factory.manufacturePojo(Pojo.class);
System.out.println(pojo);
}
}
This small test results in the following exception:
[java] Caused by: java.lang.ClassCastException: sun.reflect.generics.reflectiveObjects.WildcardTypeImpl cannot be cast to java.lang.Class
[java] at uk.co.jemos.podam.api.PodamFactoryImpl.resolveCollectionValueWhenCollectionIsPojoAttribute(PodamFactoryImpl.java:1969)
[java] at uk.co.jemos.podam.api.PodamFactoryImpl.manufactureAttributeValue(PodamFactoryImpl.java:1646)
[java] at uk.co.jemos.podam.api.PodamFactoryImpl.manufacturePojoInternal(PodamFactoryImpl.java:1485)
[java] at uk.co.jemos.podam.api.PodamFactoryImpl.manufacturePojo(PodamFactoryImpl.java:109)
[java] at PodamTest.main(PodamTest.java:27)
I created https://agileguru.atlassian.net/browse/PDM-3 for this. Would you like to fix it?
I could, but I won't have time until Monday evening.
There's no hurry. I'll go on holiday on Monday until the 30th.
I applied a quick fix for upper bounds. It works with your Pojo but it doesn't cover lower bounds or multiple bounds. BTW, it was broken also in Java 6