vipx / google-guice

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

ClassCastException: com.google.inject.internal.LinkedProviderBindingImpl cannot be cast to com.google.inject.spi.HasDependencies #507

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
The code introduced in r1167 to clean up leftover bindings (Isssue 319) does 
not check the binding implements HasDependencies before casting it:

  private Set<Dependency<?>> getInternalDependencies(BindingImpl<?> binding) {
    if(binding instanceof ConstructorBindingImpl) {
      return ((ConstructorBindingImpl)binding).getInternalDependencies();
    } else {
      return ((HasDependencies)binding).getDependencies(); // <---!
    }
  }

To reproduce the exception apply following patch, re-build, and re-test:

Index: test/com/google/inject/ImplicitBindingTest.java
===================================================================
--- test/com/google/inject/ImplicitBindingTest.java     (revision 1178)
+++ test/com/google/inject/ImplicitBindingTest.java     (working copy)
@@ -166,6 +166,7 @@
   static class Invalid {
     @Inject Valid a;
     @Inject JitValid b;
+    @Inject Provided p;
     @Inject Invalid(InvalidLinked a) {}
     @Inject void foo(InvalidInterface a) {}

The binding in this particular scenario is LinkedProviderBindingImpl which does 
not implement HasDependencies - but there may be other bindings that could 
cause the same class cast exception.

Original issue reported on code.google.com by mccu...@gmail.com on 29 Jun 2010 at 4:59

GoogleCodeExporter commented 9 years ago
Thanks for finding this, Stuart.  I really thought I checked every 
implementation before doing this, but guess I missed one.  I'll add it to the 
tests & fix.

Original comment by sberlin on 29 Jun 2010 at 5:23

GoogleCodeExporter commented 9 years ago

Original comment by sberlin on 1 Jul 2010 at 3:35

GoogleCodeExporter commented 9 years ago
fixed in r1182.

Original comment by sberlin on 3 Jul 2010 at 3:36