xiaodududu / google-guice

Automatically exported from code.google.com/p/google-guice
Apache License 2.0
0 stars 0 forks source link

Child can rebind a binding that's in parent's JIT binding set #608

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Test inside of ParentInjectorTest that should pass, but fails:

  public void testChildCannotBindToAParentJitBinding() {
    Injector parent = Guice.createInjector();
    parent.getInstance(A.class);
    try {
      parent.createChildInjector(bindsA);
      fail();
    } catch(CreationException ce) {
      // TODO: Validate the msg.
    }    
  }

Original issue reported on code.google.com by sberlin on 21 Feb 2011 at 8:00

GoogleCodeExporter commented 9 years ago
fixed in r1504.  please review!

Original comment by sberlin on 21 Feb 2011 at 9:07

GoogleCodeExporter commented 9 years ago
This seems to have caused Guice to blow up if a module binds A to B when A 
already has an "@ImplementedBy B" annotation.  Even though there's no conflict.

Original comment by kevinb@google.com on 10 Mar 2011 at 9:30

GoogleCodeExporter commented 9 years ago
So... #2 isn't actually the failure scenario.  If a module binds A to B when A 
already has @ImplementedBy, things work fine.  It also (correctly) fails if a 
module just has bind(A.class) and then later has bind(A.class).to(B.class).  
Where it fails is:

  1) Module binds Foo.
  2) Foo is @ImplementedBy(FooImpl.class)
  3) FooImpl class has a dependency on Bar
  4) Bar is @ImplementedBy(AutoBar.class)
  5) Module binds Bar to ExplicitBar.class

When figuring out the @ImplementedBy for FooImpl, it's creating a JIT binding 
for AutoBar too, and the getExistingBinding check when doing ExplicitBar sees 
AutoBar and fails.  For some reason, it *does not* fail 1) is changed to 
bind(FooImpl.class) -- that is, there's something happening specifically with 
@ImplementedBy that autowires the further dependencies.

This worked before r1504, but it created a scenario where you'd actually have 
two different bindings for Bar (one in explicit state, another in JIT), which 
Guice tries pretty hard to avoid.

Original comment by sberlin on 10 Mar 2011 at 10:23

GoogleCodeExporter commented 9 years ago
Making a new bug for this since a waterfall of them are appearing while fixing..

Original comment by sberlin on 10 Mar 2011 at 11:22