google / google/guice

Modules.override() loses source information when the current source is skipped

Open
#774 2 comments 0 reactions 0 assignees View on GitHub
imported
Dominant language
Java
Stars
12.7k
Forks
1.7k
Avg merge
11m
Merged PRs (30d)
2

Description

_From [tavianator](https://code.google.com/u/tavianator@gmail.com/) on October 07, 2013 14:04:22_

This test case:

<code language="java">
Guice.createInjector(new AbstractModule() {
    `@`Override
    protected void configure() {
        bind(String.class).toInstance("foo");
        install(Modules.override(Modules.EMPTY_MODULE).with(new AbstractModule() {
            `@`Override
            protected void configure() {
                binder().skipSources(getClass()).bind(String.class).toInstance("bar");
            }
        }));
    }
});
</code>

Produces this error:

{{{
1) A binding to java.lang.String was already configured at Test$1.configure(Test.java:74).
  at com.google.inject.util.Modules$RealOverriddenModuleBuilder$1.configure(Modules.java:172)
}}}

If the module is installed directly, without Modules.override(), it gives

{{{
1) A binding to java.lang.String was already configured at Test$1.configure(Test.java:74).
  at Test$1.configure(Test.java:75)
}}}

instead, which is a lot more helpful.

This seems like a general issue with `Elements.getElements()`: there's no way to specify sources to skip, so the bindings it creates can't have sources from above the `Elements.getElements()` call.

_Original issue: http://code.google.com/p/google-guice/issues/detail?id=774_

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.