Skip to content
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

NPE when creating type that extends generic type #36

Closed
nayan92 opened this issue Aug 9, 2017 · 1 comment
Closed

NPE when creating type that extends generic type #36

nayan92 opened this issue Aug 9, 2017 · 1 comment
Assignees
Labels

Comments

@nayan92
Copy link

nayan92 commented Aug 9, 2017

public class TestClass {

    public class GenericClass<T> {
        private T field;

        public T getField() { return this.field; }

        public void setField(T field) { this.field = field; }
    }

    public class NonGenericClass extends GenericClass<String> { }

    public static void main(String[] args) {
        new JFixture().create(NonGenericClass.class);
    }

}

This example throws NPE because it can't figure out the actual type for T when attempting to fixture field

Exception in thread "main" java.lang.NullPointerException
	at com.flextrade.jfixture.utility.SpecimenType.<init>(SpecimenType.java:37)
	at com.flextrade.jfixture.utility.SpecimenType.<init>(SpecimenType.java:12)
	at com.flextrade.jfixture.utility.SpecimenType$3.<init>(SpecimenType.java:55)
	at com.flextrade.jfixture.utility.SpecimenType.withGenericContext(SpecimenType.java:55)
	at com.flextrade.jfixture.utility.ParameterUtils.convertPossibleGenericTypeToSpecimenType(ParameterUtils.java:50)
	at com.flextrade.jfixture.builders.GenericMethodBuilder.getMethodReturnType(GenericMethodBuilder.java:36)
	at com.flextrade.jfixture.builders.GenericMethodBuilder.create(GenericMethodBuilder.java:27)
	at com.flextrade.jfixture.builders.CompositeBuilder.create(CompositeBuilder.java:26)
	at com.flextrade.jfixture.behaviours.autoproperty.AutoPropertyBuilder.create(AutoPropertyBuilder.java:22)
	at com.flextrade.jfixture.behaviours.recursion.RecursionGuard.create(RecursionGuard.java:33)
	at com.flextrade.jfixture.behaviours.noresolution.NoResolutionGuard.create(NoResolutionGuard.java:27)
	at com.flextrade.jfixture.behaviours.specimentype.SpecimenTypeInjector.create(SpecimenTypeInjector.java:26)
	at com.flextrade.jfixture.SpecimenBuilderContext.resolve(SpecimenBuilderContext.java:13)
	at com.flextrade.jfixture.behaviours.autoproperty.AutoPropertyPopulater.populateSetters(AutoPropertyPopulater.java:34)
	at com.flextrade.jfixture.behaviours.autoproperty.AutoPropertyPopulater.execute(AutoPropertyPopulater.java:23)
	at com.flextrade.jfixture.behaviours.autoproperty.AutoPropertyBuilder.create(AutoPropertyBuilder.java:25)
	at com.flextrade.jfixture.behaviours.recursion.RecursionGuard.create(RecursionGuard.java:33)
	at com.flextrade.jfixture.behaviours.noresolution.NoResolutionGuard.create(NoResolutionGuard.java:27)
	at com.flextrade.jfixture.behaviours.specimentype.SpecimenTypeInjector.create(SpecimenTypeInjector.java:26)
	at com.flextrade.jfixture.JFixture.create(JFixture.java:82)
	at com.flextrade.jfixture.JFixture.create(JFixture.java:78)
@cliffsun91 cliffsun91 self-assigned this Aug 9, 2017
@cliffsun91 cliffsun91 added the bug label Aug 9, 2017
cliffsun91 pushed a commit that referenced this issue Sep 1, 2017
Note there are more complex scenarios that aren't covered by this fix - for example if multiple generic types in an inheritance hierarchy use the same Type variable then it this won't work
richkeenan pushed a commit that referenced this issue Sep 4, 2017
* Add support for inheritance with generic types - fixes issue #36
* get travis CI builds to work again

Note there are more complex scenarios that aren't covered by this fix - for example if multiple generic types in an inheritance hierarchy use the same Type variable then it this won't work
@cliffsun91
Copy link
Contributor

This should now be supported (to a basic level) in release version 2.7.2

richkeenan pushed a commit to richkeenan/jfixture that referenced this issue May 11, 2020
…eUKLtd#36 (FlexTradeUKLtd#37)

* Add support for inheritance with generic types - fixes issue FlexTradeUKLtd#36
* get travis CI builds to work again

Note there are more complex scenarios that aren't covered by this fix - for example if multiple generic types in an inheritance hierarchy use the same Type variable then it this won't work
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants