Skip to content

Guice InjectorSourceFactory call to Class#forName should use explicit ClassLoader #1036

@DPUkyle

Description

@DPUkyle

c.r.j.guice.impl.InjectorSourceFactory makes a call to Class#forName(String) to instantiate the InjectorSource named via the cucumber.properties file.

The call to Class#forName without the ClassLoader argument will use the calling class's ClassLoader to resolve the provided class name. However, if the class to be resolved is in a child ClassLoader, this call will fail to resolve the class. This fails in my enterprise app where the cucumber JARs are in the top-level ClassLoader, but the implementation of c.r.j.guice.InjectorSource is in a child ClassLoader.

Looking to the constructors of c.r.j.JavaBackend for inspiration, the typical way to "find" the ClassLoader when one is not explicitly provided is by calling Thread.currentThread().getContextClassLoader().

I will issue a PR shortly with this small, one-line fix to c.r.j.guice.impl.InjectorSourceFactory.

This is a subset of issue #880.

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