-
Notifications
You must be signed in to change notification settings - Fork 234
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Generic field type issue (composition) #441
Comments
Every new feature comes with new bugs 😄 ER should clearly not fail with a NPE. Thank you for reporting this. |
I have spottet the same and added a simple test here: |
@reitzmichnicht you can find a raw solutions here: These branches were rejected in this project, but you still can find a solution here. |
@reitzmichnicht I'm adding your failing test here since #450 was closed. @Test
void testGenericFieldRandomization() {
// given
class Base<T> {
T t;
}
class Concrete {
Base<String> f;
}
// when
Concrete concrete = easyRandom.nextObject(Concrete.class);
// then
assertThat(concrete.f).isInstanceOf(Base.class);
} This fails with the same stacktrace as above. |
Thank you for pointing out these solutions. I just wanted to give a bit of context here about the reasons of rejecting those options.
My concern with those changes is that they are based on #426, which was rejected for the reasons explained in details here: #426 (comment). While your changes are different from those in #426, the new
The reasons why this has been rejected were detailed here: #425 (comment). |
I submitted a fix for this issue: #466. There are a number of challenges around this issue (e.g. issue #440) that my fix does not address and the project is in maintenance mode. Thus, @beans can I ask you to look at it ahead and give me a shout if it has a chance for being accepted and if so, when it can be released? |
#441 test suggested in the issue and a fix
Did hit the same issue today while upgrading a project. The ParameterizedType of I locally have a working hack (needs further polishing) where I create a fresh independent 'sub-RandomizationContext' in case I hit a field which has nothing to do with the generic hierarchy of the current class. Not quite sure though if this is the right way to approach it. |
In addition to #440 there is one more issue related to generic type support.
Consider the test:
Instead of generating correct beans it fails with NPE:
The text was updated successfully, but these errors were encountered: