Repository: j-easy/easy-random
Issue: ClassCastException on wildcard generics in collections

Hello, Trying to figure out the best way around this. I want to populate some JAX-B beans. They have fields like this:

`@XmlElementRef(name = "reportedLocation", namespace = "http://api.foo.com/v3", type = JAXBElement.class)
    protected List<JAXBElement<? extends ReportedLocation>> reportedLocations;`

I get a ClassCastException exception from this:

`Caused by: java.lang.ClassCastException: sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl cannot be cast to java.lang.Class
    at io.github.benas.randombeans.CollectionPopulator.getRandomCollection(CollectionPopulator.java:68)
    at io.github.benas.randombeans.FieldPopulator.generateRandomValue(FieldPopulator.java:93)
    at io.github.benas.randombeans.FieldPopulator.populateField(FieldPopulator.java:79)
    at io.github.benas.randombeans.EnhancedRandomImpl.populateField(EnhancedRandomImpl.java:162)
    at io.github.benas.randombeans.EnhancedRandomImpl.populateFields(EnhancedRandomImpl.java:153)
    at io.github.benas.randombeans.EnhancedRandomImpl.doPopulateBean(EnhancedRandomImpl.java:124)
    ... 203 more`

There are quite a few of these. I have a custom registry for some other abstract classes I have but I'm unsure of the best way around this one.

Another suggestion, it might be nice if the EnhancedRandom were to have a brute force mode where it never ever stops for these kinds of errors and just skips them (and logs an error maybe) 

Great library everyone!


Changed files:
random-beans/src/main/java/io/github/benas/randombeans/util/ReflectionUtils.java
random-beans/src/test/java/io/github/benas/randombeans/beans/WildCardCollectionBean.java

diff --git a/random-beans/src/main/java/io/github/benas/randombeans/util/ReflectionUtils.java b/random-beans/src/main/java/io/github/benas/randombeans/util/ReflectionUtils.java
index 4666f7b4..c2b4d263 100644
--- a/random-beans/src/main/java/io/github/benas/randombeans/util/ReflectionUtils.java
+++ b/random-beans/src/main/java/io/github/benas/randombeans/util/ReflectionUtils.java
@@ -242,7 +242,7 @@ public class ReflectionUtils {
      * @return true if the type is populatable, false otherwise
      */
     public static boolean isPopulatable(final Type type) {
-        return !isWildcardType(type) && !isTypeVariable(type) && !isCollectionType(type);
+        return !isWildcardType(type) && !isTypeVariable(type) && !isCollectionType(type) && !isParameterizedType(type);
     }
 
     /**
diff --git a/random-beans/src/test/java/io/github/benas/randombeans/beans/WildCardCollectionBean.java b/random-beans/src/test/java/io/github/benas/randombeans/beans/WildCardCollectionBean.java
index c31730c9..806452b4 100644
--- a/random-beans/src/test/java/io/github/benas/randombeans/beans/WildCardCollectionBean.java
+++ b/random-beans/src/test/java/io/github/benas/randombeans/beans/WildCardCollectionBean.java
@@ -48,6 +48,8 @@ public class WildCardCollectionBean {
 
     private List<?> unboundedWildCardTypedList;
     private List<? extends Runnable> boundedWildCardTypedList;
+    // https://github.com/benas/random-beans/issues/208
+    private List<Comparable<? extends Object>> nestedBoundedWildCardTypedList;
 
     private Queue<?> unboundedWildCardTypedQueue;
     private Queue<? extends Runnable> boundedWildCardTypedQueue;