Skip to content

DUPLICATE_ELEMENT

Googler edited this page Aug 13, 2020 · 1 revision

DUPLICATE_ELEMENT

Summary

Guice will throw a ProvisionException with DUPLICATE_ELEMENT error if:

  • Duplicate values are added to a Multibinder that does not allow duplicates
  • Duplicate keys are added to a MapBinder that does not allow duplicates

Common Causes

Unexpected duplicate element

If the Multibinder or MapBinder should not have duplicate elements then this error can be fixed by modifying the application code to prevent duplicate elements from being added. The error message from Guice contains information on what the duplicate values or keys are.

Missing permitDuplicates()

If it is expected that the Multibinder or MapBinder will have duplicates values or keys, make sure that permitDuplicates is called when the Multibinder or MapBinder is created:

final class FooModule extends AbstractModule {
  @Override
  protected void configure() {
    Multibinder.newSetBinder(binder(), String.class)
        .permitDuplicates();

    MapBinder.newMapBinder(binder(), String.class, String.class)
        .permitDuplicates();
  }
}
Clone this wiki locally