google / google/guice

Multibindings: Dependency cycle not detected or ignored

Open
#1,083 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
12.7k
Forks
1.7k
Avg merge
11m
Merged PRs (30d)
2

Description

It seems like Guice does not detect (or ignores) a dependency cycle when a multibinder is involved in the chain of dependencies. This might lead to confusing behavior, e.g. a `ProvisionException` encapsulating `java.lang.NullPointerException`.

E.g. imagine having a service provider that depends on a multibinder and some of the objects in this multibinder recursively depend on S1:

```java
class S1Provider implements Provider {
@Inject
private Set c1s; // <--- some of the C1 instances/providers depend on S1

@Override
public S1 get() {
// c1s is null here
}
}
```

This contrasts with Guice's behavior when a dependency cycle does not involve multibinders. Such cycle is reported correctly by Guice (clearly indicating that a loop is present and printing the dependency resolver stack).

Please see a runnable code example in https://github.com/atomashpolskiy/guice-multibinder-dependency-cycle

Thank you!

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.