Regression: Unable to create a random instance (brother subclasses)
See original GitHub issueConsider this snippet:
import lombok.Data;
import lombok.experimental.Accessors;
import org.jeasy.random.EasyRandom;
import org.jeasy.random.EasyRandomParameters;
public class EasyRandomTest {
public static void main(String[] args) {
EasyRandom easyRandom = new EasyRandom(new EasyRandomParameters());
System.out.println(easyRandom.nextObject(BulkOperationObjectError.class));
}
@Data
@Accessors(chain = true)
public static class ObjectError {
private String objectName;
}
@Data
@Accessors(chain = true)
public static class BulkOperationObjectError extends ObjectError {
private FieldError fieldError;
}
@Data
@Accessors(chain = true)
public static class FieldError extends ObjectError {
@Override
public FieldError setObjectName(String objectName) {
super.setObjectName(objectName);
return this;
}
}
}
I minimized the code as much as possible. In 4.2.0 it successfully creates a random instance. In 4.3.0-SNAPSHOT it fails with exception:
Exception in thread "main" org.jeasy.random.ObjectCreationException: Unable to create a random instance of type class com.trilogy.restapi.errors.EasyRandomTest$BulkOperationObjectError
at org.jeasy.random.EasyRandom.doPopulateBean(EasyRandom.java:172)
at org.jeasy.random.EasyRandom.nextObject(EasyRandom.java:100)
at com.XXX.restapi.errors.EasyRandomTest.main(EasyRandomTest.java:14)
Caused by: java.lang.IllegalArgumentException: com.trilogy.restapi.errors.EasyRandomTest$BulkOperationObjectError is not assignable from com.XXX.restapi.errors.EasyRandomTest$FieldError
at org.apache.commons.beanutils.MethodUtils.getAccessibleMethod(MethodUtils.java:793)
at org.apache.commons.beanutils.PropertyUtilsBean.getWriteMethod(PropertyUtilsBean.java:1319)
at org.apache.commons.beanutils.PropertyUtilsBean.setSimpleProperty(PropertyUtilsBean.java:2094)
at org.apache.commons.beanutils.PropertyUtilsBean.setNestedProperty(PropertyUtilsBean.java:1915)
at org.apache.commons.beanutils.PropertyUtilsBean.setProperty(PropertyUtilsBean.java:2022)
at org.jeasy.random.util.ReflectionUtils.setProperty(ReflectionUtils.java:153)
at org.jeasy.random.FieldPopulator.populateField(FieldPopulator.java:102)
at org.jeasy.random.EasyRandom.populateField(EasyRandom.java:209)
at org.jeasy.random.EasyRandom.populateFields(EasyRandom.java:198)
at org.jeasy.random.EasyRandom.doPopulateBean(EasyRandom.java:165)
... 2 more
I did not investigate it deeper yet, but for sure it may become a problem in case of version upgrade.
Issue Analytics
- State:
- Created 3 years ago
- Comments:9 (9 by maintainers)
Top Results From Across the Web
Alternative to reflection to generate objects of random ...
I have a problem with a program in Java. My program have an interface Bonus and nine subclasses that extend Bonus . I...
Read more >caret: Classification and Regression Training
Bagging can also be used to create the models. ... CAIMAN brothers: A family of powerful classification and class modeling techniques.
Read more >Random Forest Regression: When Does It Fail and Why?
In this article, we'll look at a major problem with using Random Forest for Regression which is extrapolation.
Read more >the Twisted documentation!
This document describes the optional dependencies that Twisted supports. The dependencies are python packages that. Twisted's developers have found useful ...
Read more >[Example code]-Using function output for instance initialisation in ...
I'm trying to do this: class Color: def __init__(self, r, g, b): self.r = r self.g = g self.b = b im_rgb =...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

I raised an issue https://issues.apache.org/jira/browse/BEANUTILS-541 To address an issue in easy-random we have at least two ways:
BeanUtils(dependency does not look like a good idea)The second problem with overriden field cannot be workarounded with caches flush and recreating the
PropertyUtilsBeanobject. See #438 with detailed explanations