xiaodududu / google-guice

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

Target of LinkedBinding Treated as JIT When Scoped #568

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
It's not possible to create an Injector using 
InjectorBuilder.requireExplicitBindings() if there are any scoped 
LinkedBindings that have a scoped target (implicitly via annotation). Failing 
test attached.

The problem is due to the fact that the underling InternalFactory 
(FactoryProxy) is wrapped in a ProviderToInternalFactoryAdapter (convert 
InternalFactory->Provider), then in a InternalFactoryToProviderAdapter (convert 
Provider->InternalFactory). This is necessary because the Scope instance 
requires a Provider. The key to the bug is that the 'boolean linked' parameter 
from InternalFactory.get(...) is not passed through these  conversions to call 
to the InternalFactory that does the real work.

In the test attached this is ConstructorBindingImpl.get(...), and the failure 
comes on line 195 when the class asserts that we're dealing with a linked 
binding when JIT bindings are disabled.

This can also be reproduced by simply installing a ServletModule:
new InjectorBuilder()
    .addModules(new ServletModule())
    .requireExplicitBindings()
    .build();

Yields the following error:1) Explicit bindings are required and 
com.google.inject.servlet.ManagedFilterPipeline is not explicitly bound.
  at com.google.inject.servlet.ManagedFilterPipeline.class(ManagedFilterPipeline.java:57)
  while locating com.google.inject.servlet.ManagedFilterPipeline
  at com.google.inject.servlet.InternalServletModule.configure(InternalServletModule.java:36)
  while locating com.google.inject.servlet.FilterPipeline
    for parameter 0 at com.google.inject.servlet.GuiceFilter.setPipeline(GuiceFilter.java:92)

Original issue reported on code.google.com by drew.mcl...@gmail.com on 2 Nov 2010 at 12:57

Attachments:

GoogleCodeExporter commented 9 years ago
Are you using the latest SVN head or 3.0 snapshot?  A bug that seems very 
similar to this was fixed with 
http://code.google.com/p/google-guice/source/detail?r=1175 .

Original comment by sberlin on 2 Nov 2010 at 1:32

GoogleCodeExporter commented 9 years ago
Good call. I was testing with a stale snapshot. r1175 should fix the issue.

Thanks for setting me straight.

Original comment by drew.mcl...@gmail.com on 2 Nov 2010 at 3:02