diff options
author | Tavian Barnes <tavianator@tavianator.com> | 2014-12-19 22:38:50 -0500 |
---|---|---|
committer | Tavian Barnes <tavianator@tavianator.com> | 2014-12-19 22:52:05 -0500 |
commit | 1dd0a91aa5824ebd63d1f0a038d3c9dedbe56bd1 (patch) | |
tree | 5ba4194ca9ae12194a2d0f825a19fe7c878d73e5 /core/src/com/google/inject | |
parent | ce7daa94fa8f8eebc6cf40422c56f58d93b24446 (diff) | |
download | guice-1dd0a91aa5824ebd63d1f0a038d3c9dedbe56bd1.tar.gz |
Fix https://github.com/google/guice/issues/888.
When Binder.requireExplicitBindings() is in effect, don't allow any
JIT bindings to be created in parent injectors, even JIT bindings that
are normally exempt such as the targets of linked key bindings.
Diffstat (limited to 'core/src/com/google/inject')
-rw-r--r-- | core/src/com/google/inject/internal/Errors.java | 4 | ||||
-rw-r--r-- | core/src/com/google/inject/internal/InjectorImpl.java | 14 |
2 files changed, 13 insertions, 5 deletions
diff --git a/core/src/com/google/inject/internal/Errors.java b/core/src/com/google/inject/internal/Errors.java index f684e39b..65f7e0b5 100644 --- a/core/src/com/google/inject/internal/Errors.java +++ b/core/src/com/google/inject/internal/Errors.java @@ -140,6 +140,10 @@ public final class Errors implements Serializable { return addMessage("Explicit bindings are required and %s is not explicitly bound.", key); } + public Errors jitDisabledInParent(Key<?> key) { + return addMessage("Explicit bindings are required and %s would be bound in a parent injector.", key); + } + public Errors atInjectRequired(Class clazz) { return addMessage( "Explicit @Inject annotations are required on constructors," diff --git a/core/src/com/google/inject/internal/InjectorImpl.java b/core/src/com/google/inject/internal/InjectorImpl.java index bcf481d2..e20035ac 100644 --- a/core/src/com/google/inject/internal/InjectorImpl.java +++ b/core/src/com/google/inject/internal/InjectorImpl.java @@ -101,7 +101,7 @@ final class InjectorImpl implements Injector, Lookups { NO_JIT, /** allows existing just in time bindings, but does not allow new ones */ EXISTING_JIT, - /** allows existing just in time bindings & allows new ones to be created */ + /** allows existing just in time bindings & allows new ones to be created in the current injector */ NEW_OR_EXISTING_JIT, } @@ -779,10 +779,14 @@ final class InjectorImpl implements Injector, Lookups { boolean jitDisabled, JitLimitation jitType) throws ErrorsException { // ask the parent to create the JIT binding if (parent != null) { - try { - return parent.createJustInTimeBindingRecursive(key, new Errors(), jitDisabled, - parent.options.jitDisabled ? JitLimitation.NO_JIT : jitType); - } catch (ErrorsException ignored) { + if (jitDisabled && jitType == JitLimitation.NEW_OR_EXISTING_JIT) { + throw errors.jitDisabledInParent(key).toException(); + } else { + try { + return parent.createJustInTimeBindingRecursive(key, new Errors(), jitDisabled, + parent.options.jitDisabled ? JitLimitation.NO_JIT : jitType); + } catch (ErrorsException ignored) { + } } } |