Submitting Stuart McCulloch's patch from https://github.com/sonatype/sisu-guice/blob/master/PATCHES/GUICE_288_decouple_thread_local.patch.
This rearranges the furniture a bit so we can track down some strange allocations in ThreadLocal#get().
Thanks, Stuart!
-------------
Created by MOE: http://code.google.com/p/moe-java
MOE_MIGRATED_REVID=69169927
diff --git a/core/src/com/google/inject/internal/InjectorImpl.java b/core/src/com/google/inject/internal/InjectorImpl.java
index eff9c8f..4c5c45c 100644
--- a/core/src/com/google/inject/internal/InjectorImpl.java
+++ b/core/src/com/google/inject/internal/InjectorImpl.java
@@ -128,7 +128,7 @@
if (parent != null) {
localContext = parent.localContext;
} else {
- localContext = new LocalContextThreadLocal();
+ localContext = new ThreadLocal<Object[]>();
}
}
@@ -1043,11 +1043,15 @@
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 {
@@ -1068,11 +1072,4 @@
.add("bindings", state.getExplicitBindingsThisLevel().values())
.toString();
}
-
- private static final class LocalContextThreadLocal extends ThreadLocal<Object[]> {
- @Override
- protected Object[] initialValue() {
- return new Object[1];
- }
- }
}