Skip to content

NPE when using simple generic class #59

@TWiStErRob

Description

@TWiStErRob

The following classes make JFixture throw an NPE (similar to #29, but not inner class):

class SomeClass {
    final Wrapper<String> wrapper;

    public SomeClass(Wrapper<String> data) {
        this.wrapper = data;
    }
}

class Wrapper<T> {
    final T data;

    public Wrapper(T data) {
        this.data = data;
    }
}
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.utility.ParameterUtils.getParameterTypes(ParameterUtils.java:43)
	at com.flextrade.jfixture.utility.ParameterUtils.getConstructorArguments(ParameterUtils.java:15)
	at com.flextrade.jfixture.builders.GenericConstructorRelay.create(GenericConstructorRelay.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.builders.ClassToConstructorRelay.create(ClassToConstructorRelay.java:51)
	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.utility.ParameterUtils.convertTypesToInstances(ParameterUtils.java:28)
	at com.flextrade.jfixture.utility.ParameterUtils.getConstructorArguments(ParameterUtils.java:16)
	at com.flextrade.jfixture.builders.GenericConstructorRelay.create(GenericConstructorRelay.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.builders.ClassToConstructorRelay.create(ClassToConstructorRelay.java:51)
	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.JFixture.create(JFixture.java:82)
	at com.flextrade.jfixture.JFixture.create(JFixture.java:78)
	at SomeClassJFixtureTest.test(SomeClassJFixtureTest.java:13)

Here's the test to drive it:

import com.flextrade.jfixture.JFixture;

import org.junit.Test;

import static org.junit.Assert.assertNotNull;

public class SomeClassJFixtureTest {

    @Test
    public void test() {
        SomeClass fixt = new JFixture().create(SomeClass.class);
        assertNotNull(fixt);
        assertNotNull(fixt.wrapper);
        assertNotNull(fixt.wrapper.data);
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions