Repository: wicket Updated Branches: refs/heads/wicket-7.x ae7f324dd -> 242d4e9e1
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/242d4e9e Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/242d4e9e Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/242d4e9e Branch: refs/heads/wicket-7.x Commit: 242d4e9e1c32b2cb5c03a657ecafdd50dc9f6c30 Parents: ae7f324 Author: Emond Papegaaij <[email protected]> Authored: Tue Jan 30 13:51:29 2018 +0100 Committer: Emond Papegaaij <[email protected]> Committed: Tue Jan 30 13:52:32 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/242d4e9e/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 05fcaa0..ba0deb4 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. @@ -299,14 +300,6 @@ public class PageStoreManager extends AbstractPageManager ClassNotFoundException { s.defaultReadObject(); - - storingTouchedPages = new ThreadLocal<Boolean>() - { - protected Boolean initialValue() - { - return Boolean.FALSE; - }; - }; afterReadObject = new ArrayList<>(); @@ -338,7 +331,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; @@ -445,14 +438,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(); } } }
