diff options
author | Tavian Barnes <tavianator@tavianator.com> | 2015-01-19 22:17:33 -0500 |
---|---|---|
committer | Tavian Barnes <tavianator@tavianator.com> | 2015-01-19 22:44:12 -0500 |
commit | fdbdc63cc56fd2e8d8e45180261be21696f89a8d (patch) | |
tree | 9b305b5838659e0c5686150e67b747dc2fe69ab9 /core | |
parent | a59c18dba735563ebaf1792c4e787552e72374f1 (diff) | |
download | guice-fdbdc63cc56fd2e8d8e45180261be21696f89a8d.tar.gz |
Fix linked binding behavior with requireExplicitBindings() in the parent.
The old behavior was to try to create the binding in the parent,
swallow the error, and create it in the child. This restores that
behavior, as bindings created in the current injector shouldn't be
prohibited.
Diffstat (limited to 'core')
-rw-r--r-- | core/src/com/google/inject/internal/InjectorImpl.java | 16 | ||||
-rw-r--r-- | core/test/com/google/inject/JitBindingsTest.java | 7 |
2 files changed, 13 insertions, 10 deletions
diff --git a/core/src/com/google/inject/internal/InjectorImpl.java b/core/src/com/google/inject/internal/InjectorImpl.java index be1c4c8b..eef7d98e 100644 --- a/core/src/com/google/inject/internal/InjectorImpl.java +++ b/core/src/com/google/inject/internal/InjectorImpl.java @@ -779,14 +779,16 @@ final class InjectorImpl implements Injector, Lookups { boolean jitDisabled, JitLimitation jitType) throws ErrorsException { // ask the parent to create the JIT binding if (parent != null) { - if (jitDisabled && jitType == JitLimitation.NEW_OR_EXISTING_JIT) { + if (jitType == JitLimitation.NEW_OR_EXISTING_JIT + && jitDisabled && !parent.options.jitDisabled) { + // If the binding would be forbidden here but allowed in a parent, report an error instead throw errors.jitDisabledInParent(key).toException(); - } else { - try { - return parent.createJustInTimeBindingRecursive(key, new Errors(), jitDisabled, - parent.options.jitDisabled ? JitLimitation.NO_JIT : jitType); - } catch (ErrorsException ignored) { - } + } + + try { + return parent.createJustInTimeBindingRecursive(key, new Errors(), jitDisabled, + parent.options.jitDisabled ? JitLimitation.NO_JIT : jitType); + } catch (ErrorsException ignored) { } } diff --git a/core/test/com/google/inject/JitBindingsTest.java b/core/test/com/google/inject/JitBindingsTest.java index ec770958..243c53e2 100644 --- a/core/test/com/google/inject/JitBindingsTest.java +++ b/core/test/com/google/inject/JitBindingsTest.java @@ -326,10 +326,10 @@ public class JitBindingsTest extends TestCase { @Override protected void configure() { bind(Foo.class).to(FooImpl.class); - bind(FooImpl.class); } }); ensureWorks(child, Foo.class, Bar.class); + ensureFails(child, ALLOW_BINDING, FooImpl.class); ensureInChild(parent, FooImpl.class, Foo.class); // TODO(sameb): FooBar may or may not be in a child injector, depending on if GC has run. // We should fix failed child injectors to remove their contents from the parent blacklist @@ -344,6 +344,8 @@ public class JitBindingsTest extends TestCase { } }); ensureWorks(grandchild, FooBar.class, Foo.class, Bar.class); + ensureFails(grandchild, ALLOW_BINDING, FooImpl.class); + ensureFails(child, ALLOW_BINDING, FooImpl.class); ensureInChild(parent, FooImpl.class, FooBar.class, Foo.class); } @@ -426,7 +428,6 @@ public class JitBindingsTest extends TestCase { public void configure() { bind(Foo.class).to(FooImpl.class); expose(Foo.class); - bind(FooImpl.class); } }); } @@ -596,7 +597,7 @@ public class JitBindingsTest extends TestCase { assertEquals(1, expected.getErrorMessages().size()); } } - + private void ensureWorks(Injector injector, Class<?>... classes) { for(int i = 0; i < classes.length; i++) { injector.getInstance(classes[i]); |