Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,7 @@ void validate() {
}

void injectMembers() {
InternalContext context = injector.enterContext();
try {
try (InternalContext context = injector.enterContext()) {
boolean isStageTool = injector.options.stage == Stage.TOOL;
for (SingleMemberInjector memberInjector : memberInjectors) {
// Run injections if we're not in tool stage (ie, PRODUCTION or DEV),
Expand All @@ -151,8 +150,6 @@ void injectMembers() {
}
}
}
} finally {
context.close();
}
}
}
Expand Down
5 changes: 1 addition & 4 deletions core/src/com/google/inject/internal/InjectorImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -1143,14 +1143,11 @@ <T> Provider<T> getProviderOrThrow(final Dependency<T> dependency, Errors errors
return new Provider<T>() {
@Override
public T get() {
InternalContext currentContext = enterContext();
try {
try (InternalContext currentContext = enterContext()) {
T t = internalFactory.get(currentContext, dependency, false);
return t;
} catch (InternalProvisionException e) {
throw e.addSource(dependency).toProvisionException();
} finally {
currentContext.close();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,8 @@ void loadEagerSingletons(InjectorImpl injector, Stage stage, final Errors errors
// jit bindings must be accessed while holding the lock.
candidateBindings.addAll(injector.getJitBindingData().getJitBindings().values());
}
InternalContext context = injector.enterContext();
try {

try (InternalContext context = injector.enterContext()) {
for (BindingImpl<?> binding : candidateBindings) {
if (isEagerSingleton(injector, binding, stage)) {
Dependency<?> dependency = Dependency.get(binding.getKey());
Expand All @@ -216,8 +216,6 @@ void loadEagerSingletons(InjectorImpl injector, Stage stage, final Errors errors
}
}
}
} finally {
context.close();
}
}

Expand Down
5 changes: 1 addition & 4 deletions core/src/com/google/inject/internal/MembersInjectorImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,7 @@ void injectAndNotify(
if (instance == null) {
return;
}
final InternalContext context = injector.enterContext();
try {
try (InternalContext context = injector.enterContext()) {
if (provisionCallback != null && provisionCallback.hasListeners()) {
provisionCallback.provision(
context,
Expand All @@ -100,8 +99,6 @@ public T call() throws InternalProvisionException {
} else {
injectMembers(instance, context, toolableOnly);
}
} finally {
context.close();
}

// TODO: We *could* notify listeners too here,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,14 @@ public ProviderToInternalFactoryAdapter(

@Override
public T get() {
InternalContext context = injector.enterContext();
try {
try (InternalContext context = injector.enterContext()) {
// Always pretend that we are a linked binding, to support
// scoping implicit bindings. If we are not actually a linked
// binding, we'll fail properly elsewhere in the chain.
T t = internalFactory.get(context, context.getDependency(), true);
return t;
} catch (InternalProvisionException e) {
throw e.toProvisionException();
} finally {
context.close();
}
}

Expand Down