podam icon indicating copy to clipboard operation
podam copied to clipboard

Podam doesn't handle whildcard generics with JDK1.7

Open daivanov opened this issue 13 years ago • 4 comments

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)

daivanov avatar May 17 '13 18:05 daivanov

I created https://agileguru.atlassian.net/browse/PDM-3 for this. Would you like to fix it?

mtedone avatar May 17 '13 18:05 mtedone

I could, but I won't have time until Monday evening.

daivanov avatar May 17 '13 21:05 daivanov

There's no hurry. I'll go on holiday on Monday until the 30th.

mtedone avatar May 17 '13 21:05 mtedone

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

mtedone avatar May 17 '13 21:05 mtedone