diff --git a/portal-kernel/src/com/liferay/portal/kernel/util/SessionClicks.java b/portal-kernel/src/com/liferay/portal/kernel/util/SessionClicks.java
index e9b6947122822ac4aca92f701316ccede88de7fd..401ea5e54359594b7701d410cb77505ae2996cad 100644
--- a/portal-kernel/src/com/liferay/portal/kernel/util/SessionClicks.java
+++ b/portal-kernel/src/com/liferay/portal/kernel/util/SessionClicks.java
@@ -21,6 +21,7 @@ import com.liferay.portal.kernel.portlet.PortalPreferences;
 import com.liferay.portal.kernel.portlet.PortletPreferencesFactoryUtil;
 
 import java.util.ConcurrentModificationException;
+import java.util.Enumeration;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpSession;
@@ -84,17 +85,7 @@ public class SessionClicks {
 		HttpServletRequest request, String namespace, String key,
 		String value) {
 
-		if ((key.length() > _SESSION_CLICKS_MAX_SIZE_TERMS) ||
-			(value.length() > _SESSION_CLICKS_MAX_SIZE_TERMS)) {
-
-			if (_log.isWarnEnabled()) {
-				_log.warn(
-					StringBundler.concat(
-						"Session clicks has attempted to exceed the maximum ",
-						"size allowed for keys or values with {key=", key,
-						", value=", value, "}"));
-			}
-
+		if (!_isValidKeyValue(key, value)) {
 			return;
 		}
 
@@ -105,18 +96,9 @@ public class SessionClicks {
 
 				int size = portalPreferences.size();
 
-				if (size <= _SESSION_CLICKS_MAX_ALLOWED_VALUES) {
+				if (_isValidSize(size, key, value)) {
 					portalPreferences.setValue(namespace, key, value);
 				}
-				else {
-					if (_log.isWarnEnabled()) {
-						_log.warn(
-							StringBundler.concat(
-								"Session clicks has attempted to exceed the ",
-								"maximum number of allowed values with {key=",
-								key, ", value=", value, "}"));
-					}
-				}
 
 				break;
 			}
@@ -137,13 +119,60 @@ public class SessionClicks {
 	public static void put(
 		HttpSession session, String namespace, String key, String value) {
 
-		String sessionKey = namespace.concat(
-			StringPool.COLON
-		).concat(
-			key
-		);
+		if (!_isValidKeyValue(key, value)) {
+			return;
+		}
+
+		Enumeration<String> enumeration = session.getAttributeNames();
+
+		int size = 0;
+
+		while (enumeration.hasMoreElements()) {
+			enumeration.nextElement();
+
+			size++;
+		}
+
+		if (_isValidSize(size, key, value)) {
+			String sessionKey = StringBundler.concat(
+				namespace, StringPool.COLON, key);
+
+			session.setAttribute(sessionKey, value);
+		}
+	}
+
+	private static boolean _isValidKeyValue(String key, String value) {
+		if ((key.length() <= _SESSION_CLICKS_MAX_SIZE_TERMS) &&
+			(value.length() <= _SESSION_CLICKS_MAX_SIZE_TERMS)) {
+
+			return true;
+		}
+
+		if (_log.isWarnEnabled()) {
+			_log.warn(
+				StringBundler.concat(
+					"Session clicks has attempted to exceed the maximum size ",
+					"allowed for keys or values with key \"", key,
+					"\" and value \"", value, "\""));
+		}
+
+		return false;
+	}
+
+	private static boolean _isValidSize(int size, String key, String value) {
+		if (size < _SESSION_CLICKS_MAX_ALLOWED_VALUES) {
+			return true;
+		}
+
+		if (_log.isWarnEnabled()) {
+			_log.warn(
+				StringBundler.concat(
+					"Session clicks has attempted to exceed the maximum ",
+					"number of allowed values with key \"", key,
+					"\" and value \"", value, "\""));
+		}
 
-		session.setAttribute(sessionKey, value);
+		return false;
 	}
 
 	private static final String _DEFAULT_NAMESPACE =