This is an automated email from the ASF dual-hosted git repository.

markt pushed a commit to branch 10.1.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git


The following commit(s) were added to refs/heads/10.1.x by this push:
     new f818862f36 Optimize when call getSessionCookieName & 
getSessionUriParamName (#660)
f818862f36 is described below

commit f818862f3605ee02556f42dd3288fca8ebf14b14
Author: Herb <thegreengoo...@gmail.com>
AuthorDate: Wed Sep 6 21:41:53 2023 +0900

    Optimize when call getSessionCookieName & getSessionUriParamName (#660)
    
    Reduce duplicate / unnecessary code
---
 java/org/apache/catalina/util/SessionConfig.java | 27 +++++-------------------
 1 file changed, 5 insertions(+), 22 deletions(-)

diff --git a/java/org/apache/catalina/util/SessionConfig.java 
b/java/org/apache/catalina/util/SessionConfig.java
index 6957285912..7720adcbf8 100644
--- a/java/org/apache/catalina/util/SessionConfig.java
+++ b/java/org/apache/catalina/util/SessionConfig.java
@@ -32,14 +32,7 @@ public class SessionConfig {
      * @return the cookie name for the context
      */
     public static String getSessionCookieName(Context context) {
-
-        String result = getConfiguredSessionCookieName(context);
-
-        if (result == null) {
-            result = DEFAULT_SESSION_COOKIE_NAME;
-        }
-
-        return result;
+        return getConfiguredSessionCookieName(context, 
DEFAULT_SESSION_COOKIE_NAME);
     }
 
     /**
@@ -49,19 +42,11 @@ public class SessionConfig {
      * @return the parameter name for the session
      */
     public static String getSessionUriParamName(Context context) {
-
-        String result = getConfiguredSessionCookieName(context);
-
-        if (result == null) {
-            result = DEFAULT_SESSION_PARAMETER_NAME;
-        }
-
-        return result;
+        return getConfiguredSessionCookieName(context, 
DEFAULT_SESSION_PARAMETER_NAME);
     }
 
 
-    private static String getConfiguredSessionCookieName(Context context) {
-
+    private static String getConfiguredSessionCookieName(Context context, 
String defaultName) {
         // Priority is:
         // 1. Cookie name defined in context
         // 2. Cookie name configured for app
@@ -72,15 +57,13 @@ public class SessionConfig {
                 return cookieName;
             }
 
-            SessionCookieConfig scc =
-                context.getServletContext().getSessionCookieConfig();
+            SessionCookieConfig scc = 
context.getServletContext().getSessionCookieConfig();
             cookieName = scc.getName();
             if (cookieName != null && cookieName.length() > 0) {
                 return cookieName;
             }
         }
-
-        return null;
+        return defaultName;
     }
 
 


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to