Repository: wicket Updated Branches: refs/heads/master d21bfe325 -> a6b48110f
WICKET-6522: move ThreadLocal to a static field to prevent leaks Project: http://git-wip-us.apache.org/repos/asf/wicket/repo Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/a6b48110 Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/a6b48110 Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/a6b48110 Branch: refs/heads/master Commit: a6b48110f130cb3074b78f8add29b59d4a0ecc7f Parents: d21bfe3 Author: Emond Papegaaij <[email protected]> Authored: Tue Jan 30 13:51:29 2018 +0100 Committer: Emond Papegaaij <[email protected]> Committed: Tue Jan 30 13:51:29 2018 +0100 ---------------------------------------------------------------------- .../apache/wicket/page/PageStoreManager.java | 55 +++++++++----------- 1 file changed, 24 insertions(+), 31 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/wicket/blob/a6b48110/wicket-core/src/main/java/org/apache/wicket/page/PageStoreManager.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/main/java/org/apache/wicket/page/PageStoreManager.java b/wicket-core/src/main/java/org/apache/wicket/page/PageStoreManager.java index 97d5b59..88c1645 100644 --- a/wicket-core/src/main/java/org/apache/wicket/page/PageStoreManager.java +++ b/wicket-core/src/main/java/org/apache/wicket/page/PageStoreManager.java @@ -43,10 +43,29 @@ public class PageStoreManager extends AbstractPageManager private static final String ATTRIBUTE_NAME = "wicket:persistentPageManagerData"; - private final IPageStore pageStore; + /** + * A flag indicating whether this session entry is being re-set in the Session. + * <p> + * Web containers intercept + * {@link javax.servlet.http.HttpSession#setAttribute(String, Object)} to detect changes and + * replicate the session. If the attribute has been already bound in the session then + * {@link #valueUnbound(HttpSessionBindingEvent)} might get called - this flag + * helps us to ignore the invocation in that case. + * + * @see #valueUnbound(HttpSessionBindingEvent) + */ + private static final ThreadLocal<Boolean> STORING_TOUCHED_PAGES = new ThreadLocal<Boolean>() + { + protected Boolean initialValue() + { + return Boolean.FALSE; + }; + }; + private final IPageStore pageStore; + private final String applicationName; - + /** * Construct. * @@ -93,24 +112,6 @@ public class PageStoreManager extends AbstractPageManager private transient List<IManageablePage> sessionCache; private transient List<Object> afterReadObject; - /** - * A flag indicating whether this session entry is being re-set in the Session. - * <p> - * Web containers intercept - * {@link javax.servlet.http.HttpSession#setAttribute(String, Object)} to detect changes and - * replicate the session. If the attribute has been already bound in the session then - * {@link #valueUnbound(HttpSessionBindingEvent)} might get called - this flag - * helps us to ignore the invocation in that case. - * - * @see #valueUnbound(HttpSessionBindingEvent) - */ - private transient ThreadLocal<Boolean> storingTouchedPages = new ThreadLocal<Boolean>() - { - protected Boolean initialValue() - { - return Boolean.FALSE; - }; - }; /** * Construct. @@ -313,14 +314,6 @@ public class PageStoreManager extends AbstractPageManager { s.defaultReadObject(); - storingTouchedPages = new ThreadLocal<Boolean>() - { - protected Boolean initialValue() - { - return Boolean.FALSE; - }; - }; - afterReadObject = new ArrayList<>(); List<Serializable> l = (List<Serializable>)s.readObject(); @@ -351,7 +344,7 @@ public class PageStoreManager extends AbstractPageManager @Override public void valueUnbound(HttpSessionBindingEvent event) { - if (storingTouchedPages == null || storingTouchedPages.get()) + if (STORING_TOUCHED_PAGES.get()) { // triggered by #storeTouchedPages(), so do not remove the data return; @@ -468,14 +461,14 @@ public class PageStoreManager extends AbstractPageManager pageStore.storePage(entry.sessionId, page); } - entry.storingTouchedPages.set(true); + STORING_TOUCHED_PAGES.set(true); try { setSessionAttribute(getAttributeName(), entry); } finally { - entry.storingTouchedPages.set(false); + STORING_TOUCHED_PAGES.remove(); } } }
