aboutsummaryrefslogtreecommitdiffstats
path: root/server/src
diff options
context:
space:
mode:
authorArtur Signell <artur@vaadin.com>2013-03-26 01:41:48 +0200
committerArtur Signell <artur@vaadin.com>2013-04-03 10:14:53 +0300
commit2b5f6ccc1e9ae5c9c8c88dc3195020eaa27a3be6 (patch)
tree7cf5509b4cd8f198bce900bfde380cd15e2ab9d4 /server/src
parent5d8b1862b63d32070b4084d7e49cae1f4bc66953 (diff)
downloadvaadin-framework-2b5f6ccc1e9ae5c9c8c88dc3195020eaa27a3be6.tar.gz
vaadin-framework-2b5f6ccc1e9ae5c9c8c88dc3195020eaa27a3be6.zip
Backported fix of minimal (empty hashmap) leak on redeploy (#9993)
Change-Id: I9933c21ab8449378269c577c9622d75586590e45 Merge: no
Diffstat (limited to 'server/src')
-rw-r--r--server/src/com/vaadin/util/CurrentInstance.java35
1 files changed, 26 insertions, 9 deletions
diff --git a/server/src/com/vaadin/util/CurrentInstance.java b/server/src/com/vaadin/util/CurrentInstance.java
index adf6d963c3..595c162e7e 100644
--- a/server/src/com/vaadin/util/CurrentInstance.java
+++ b/server/src/com/vaadin/util/CurrentInstance.java
@@ -36,6 +36,10 @@ public class CurrentInstance implements Serializable {
@Override
protected Map<Class<?>, CurrentInstance> childValue(
Map<Class<?>, CurrentInstance> parentValue) {
+ if (parentValue == null) {
+ return null;
+ }
+
Map<Class<?>, CurrentInstance> value = new HashMap<Class<?>, CurrentInstance>();
// Copy all inheritable values to child map
@@ -47,11 +51,6 @@ public class CurrentInstance implements Serializable {
return value;
}
-
- @Override
- protected Map<java.lang.Class<?>, CurrentInstance> initialValue() {
- return new HashMap<Class<?>, CurrentInstance>();
- }
};
private CurrentInstance(Object instance, boolean inheritable) {
@@ -68,7 +67,11 @@ public class CurrentInstance implements Serializable {
* if there is no current instance.
*/
public static <T> T get(Class<T> type) {
- CurrentInstance currentInstance = instances.get().get(type);
+ Map<Class<?>, CurrentInstance> map = instances.get();
+ if (map == null) {
+ return null;
+ }
+ CurrentInstance currentInstance = map.get(type);
if (currentInstance != null) {
return type.cast(currentInstance.instance);
} else {
@@ -110,11 +113,25 @@ public class CurrentInstance implements Serializable {
}
private static <T> void set(Class<T> type, T instance, boolean inheritable) {
+ Map<Class<?>, CurrentInstance> map = instances.get();
if (instance == null) {
- instances.get().remove(type);
+ // remove the instance
+ if (map == null) {
+ return;
+ }
+ map.remove(type);
+ if (map.isEmpty()) {
+ instances.remove();
+ map = null;
+ }
} else {
assert type.isInstance(instance) : "Invald instance type";
- CurrentInstance previousInstance = instances.get().put(type,
+ if (map == null) {
+ map = new HashMap<Class<?>, CurrentInstance>();
+ instances.set(map);
+ }
+
+ CurrentInstance previousInstance = map.put(type,
new CurrentInstance(instance, inheritable));
if (previousInstance != null) {
assert previousInstance.inheritable == inheritable : "Inheritable status mismatch for "
@@ -127,6 +144,6 @@ public class CurrentInstance implements Serializable {
* Clears all current instances.
*/
public static void clearAll() {
- instances.get().clear();
+ instances.remove();
}
}