Skip to content

CIRCULAR_PROXY_DISABLED

Googler edited this page Aug 11, 2020 · 1 revision

CIRCULAR_PROXY_DISABLED

Summary

Guice will throw a CIRCULAR_PROXY_DISABLED error when it runs into a circular dependency cycle and the injector is configured to disable circular proxy.

Example:

final class Foo {
  @Inject
  Foo(Bar bar) {
    ...
  }
}

final class Bar {
  @Inject
  Bar(Baz baz) {
    ...
  }
}

final class Baz {
  @Inject
  Baz(Foo foo) {
    ...
  }
}

In the above example, in order to create instance of Foo, Guice runs into a circular dependency cycle: Foo -> Bar -> Baz -> Foo. In a real application the circular dependency cycle might be much more complicated and less obvious than this example.

Common Causes

A new circular dependency cycle is introduced

Take the example from the summary section above. Class Baz is changed from:

final class Baz {
  @Inject
  Baz() {
    ...
  }
}

to

final class Baz {
  // Baz now depends on Foo
  @Inject
  Baz(Foo foo) {
    ...
  }
}

By depending on Foo in Baz, a new circular dependency cycle that previously does not exist is introduced.

To fix this type of issues, see ways to avoid circular dependencies.

NOTE: Depending on the types involved in the circular cycle, you may get a CAN_NOT_PROXY_CLASS error instead of CIRCULAR_PROXY_DISABLED.

Circular proxy feature is disabled

If no new circular dependency cycle was added and you suddenly start getting CIRCULAR_PROXY_DISABLED error then it's likely that some module that your application installs has disabled circular proxy feature in Guice.

There are two ways to fix this:

  • (recommended) Break the circular dependencies.
  • (discouraged) Re-enable circular proxy feature in Guice by removing the code that calls binder().disableCircularProxies().
Clone this wiki locally