Migrated attachment for Guice issue 288, comment 88
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Description: Decouple the context ThreadLocal from the containing Injector/ClassLoader | |
Author: Stuart McCulloch <mcculls@gmail.com> | |
Bug-Google: http://code.google.com/p/google-guice/issues/detail?id=288 | |
Last-Update: 2012-08-07 | |
diff --git a/core/src/com/google/inject/internal/InjectorImpl.java b/core/src/com/google/inject/internal/InjectorImpl.java | |
index ee5e2d6..f40bc0f 100644 | |
--- a/core/src/com/google/inject/internal/InjectorImpl.java | |
+++ b/core/src/com/google/inject/internal/InjectorImpl.java | |
@@ -125,12 +125,7 @@ final class InjectorImpl implements Injector, Lookups { | |
if (parent != null) { | |
localContext = parent.localContext; | |
} else { | |
- localContext = new ThreadLocal<Object[]>() { | |
- @Override | |
- protected Object[] initialValue() { | |
- return new Object[1]; | |
- } | |
- }; | |
+ localContext = new ThreadLocal<Object[]>(); | |
} | |
} | |
@@ -1037,11 +1032,15 @@ final class InjectorImpl implements Injector, Lookups { | |
return getProvider(type).get(); | |
} | |
- final ThreadLocal<Object[]> localContext; | |
+ private final ThreadLocal<Object[]> localContext; | |
/** Looks up thread local context. Creates (and removes) a new context if necessary. */ | |
<T> T callInContext(ContextualCallable<T> callable) throws ErrorsException { | |
Object[] reference = localContext.get(); | |
+ if (reference == null) { | |
+ reference = new Object[1]; | |
+ localContext.set(reference); | |
+ } | |
if (reference[0] == null) { | |
reference[0] = new InternalContext(); | |
try { |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment