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

UnsatisfiableDependenciesException with Components in Picocontainer after update to version 7.12.0 #2762

Closed
cfroh1 opened this issue May 25, 2023 · 4 comments · Fixed by #2764
Assignees
Labels
🐛 bug Defect / Bug

Comments

@cfroh1
Copy link

cfroh1 commented May 25, 2023

👓 What did you see?

Dependencies of classes treated by Picocontainer as components (e.g. by implementing the 'Disposable' interface) cannot be resolved in version 7.12.0. Class dependency hierarchies without components in them are no problem. If the component itself has no dependencies and is only injected, it works fine as well.

✅ What did you expect to see?

I expect a working constructor dependency injection as in version 7.11.2, which was independent whether a class is treated as component or not.

📦 Which tool/library version are you using?

Cucumber JVM 7.12.0

🔬 How could we reproduce it?

Steps to reproduce the behavior:

  1. Create a cucumber test dependent on class A (Constructor DI)
  2. Implement the Disposable interface in class A
  3. Add a dependency from class A to another class B (Constructor DI)
  4. Start the test: class B is now an unsatisfied dependency of class A

📚 Any additional context?

Probably caused by changes from #2724

@jkronegg
Copy link
Contributor

jkronegg commented May 26, 2023

Can you provide a code sample please ?

Edit: I could reproduce the issue by making the class StepDefinitionsWithTransitiveDependencies.FirstDependency to implement Disposable. The error is:

org.picocontainer.injectors.AbstractInjector$UnsatisfiableDependenciesException: io.cucumber.picocontainer.StepDefinitionsWithTransitiveDependencies$FirstDependency has unsatisfied dependency 'class io.cucumber.picocontainer.StepDefinitionsWithTransitiveDependencies$SecondDependency' for constructor 'public io.cucumber.picocontainer.StepDefinitionsWithTransitiveDependencies$FirstDependency(io.cucumber.picocontainer.StepDefinitionsWithTransitiveDependencies$SecondDependency)' from org.picocontainer.DefaultPicoContainer@6c80d78a:1<|

at org.picocontainer.injectors.ConstructorInjector.getGreediestSatisfiableConstructor(ConstructorInjector.java:191)
at org.picocontainer.injectors.ConstructorInjector.getGreediestSatisfiableConstructor(ConstructorInjector.java:110)
at org.picocontainer.injectors.ConstructorInjector.access$100(ConstructorInjector.java:51)
at org.picocontainer.injectors.ConstructorInjector$1.run(ConstructorInjector.java:331)
at org.picocontainer.injectors.AbstractInjector$ThreadLocalCyclicDependencyGuard.observe(AbstractInjector.java:270)
at org.picocontainer.injectors.ConstructorInjector.getComponentInstance(ConstructorInjector.java:364)
at org.picocontainer.injectors.AbstractInjectionFactory$LifecycleAdapter.getComponentInstance(AbstractInjectionFactory.java:56)

I'll fix the issue.

@jkronegg jkronegg added the 🐛 bug Defect / Bug label May 26, 2023
@cfroh1
Copy link
Author

cfroh1 commented May 26, 2023

Thanks for the fast reply.

Sure, you can find a complete minimal example here:
https://github.com/cfroh1/cucumber_UnsatisfiableDependenciesException_sample

Otherwise, the relevant classes are:

MyStepdefs.class

public class MyStepdefs {

    private final ComponentDependency componentDependency;

    public MyStepdefs(final ComponentDependency componentDependency) {
        this.componentDependency = componentDependency;
    }

    @Given("Some step")
    public void someStep() {
    }
}

ComponentDependency.class

// You could also use a different pico component interface like Startable
public class ComponentDependency implements Disposable {

    private final PojoDependency pojoDependency;

    public ComponentDependency(final PojoDependency pojoDependency) {
        this.pojoDependency = pojoDependency;
    }

    @Override
    public void dispose() {

    }
}

PojoDependency.class

public class PojoDependency {

}

Running with Cucumber JVM 7.12.0 this will result in the following exception:

org.picocontainer.injectors.AbstractInjector$UnsatisfiableDependenciesException: org.example.ComponentDependency has unsatisfied dependency 'class org.example.PojoDependency' for constructor 'public org.example.ComponentDependency(org.example.PojoDependency)' from org.picocontainer.DefaultPicoContainer

@jkronegg
Copy link
Contributor

jkronegg commented Jun 2, 2023

@cfroh1 this issue is solved in cucumber 7.12.1

@cfroh1
Copy link
Author

cfroh1 commented Jun 5, 2023

Awesome, thanks a lot! :)

jkronegg pushed a commit that referenced this issue Jun 6, 2023
jkronegg pushed a commit that referenced this issue Jun 6, 2023
jkronegg pushed a commit that referenced this issue Aug 4, 2023
jkronegg pushed a commit that referenced this issue Aug 4, 2023
jkronegg pushed a commit that referenced this issue Oct 13, 2024
jkronegg pushed a commit that referenced this issue Oct 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Defect / Bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants