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

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

commit bc543e9d0657a9eba416f6095979afc8a34603bc
Author: Mark Thomas <[email protected]>
AuthorDate: Wed May 27 09:47:04 2026 +0100

    Re-work null check
    
    The previous code would still have triggered an NPE as
    super.initInternal() calls getObjectNameKeyProperties() which depends on
    a non-null return from getContainer()
---
 java/org/apache/catalina/valves/LocalStrings.properties |  1 +
 java/org/apache/catalina/valves/ValveBase.java          | 10 +++++-----
 2 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/java/org/apache/catalina/valves/LocalStrings.properties 
b/java/org/apache/catalina/valves/LocalStrings.properties
index 35a458f4d4..f421f3754b 100644
--- a/java/org/apache/catalina/valves/LocalStrings.properties
+++ b/java/org/apache/catalina/valves/LocalStrings.properties
@@ -176,3 +176,4 @@ stuckThreadDetectionValve.notifyStuckThreadCompleted=Thread 
[{0}] (id=[{3}]) was
 stuckThreadDetectionValve.notifyStuckThreadDetected=Thread [{0}] (id=[{6}]) 
has been active for [{1}] milliseconds (since [{2}]) to serve the same request 
for [{4}] and may be stuck (configured threshold for this 
StuckThreadDetectionValve is [{5}] seconds). There is/are [{3}] thread(s) in 
total that are monitored by this Valve and may be stuck.
 stuckThreadDetectionValve.notifyStuckThreadInterrupted=Thread [{0}] (id=[{5}]) 
has been interrupted because it was active for [{1}] milliseconds (since [{2}]) 
to serve the same request for [{3}] and was probably stuck (configured 
interruption threshold for this StuckThreadDetectionValve is [{4}] seconds).
 
+valveBase.noContainer=A Container must be configured before a Valve can be 
initialized
diff --git a/java/org/apache/catalina/valves/ValveBase.java 
b/java/org/apache/catalina/valves/ValveBase.java
index 0bbf8b81e8..b5318392f9 100644
--- a/java/org/apache/catalina/valves/ValveBase.java
+++ b/java/org/apache/catalina/valves/ValveBase.java
@@ -25,7 +25,6 @@ import org.apache.catalina.Valve;
 import org.apache.catalina.util.LifecycleMBeanBase;
 import org.apache.catalina.util.ToStringUtil;
 import org.apache.juli.logging.Log;
-import org.apache.juli.logging.LogFactory;
 import org.apache.tomcat.util.res.StringManager;
 
 /**
@@ -35,8 +34,6 @@ import org.apache.tomcat.util.res.StringManager;
  */
 public abstract class ValveBase extends LifecycleMBeanBase implements 
Contained, Valve {
 
-    private static final Log log = LogFactory.getLog(ValveBase.class);
-
     /**
      * StringManager for internationalized strings.
      */
@@ -146,9 +143,12 @@ public abstract class ValveBase extends LifecycleMBeanBase 
implements Contained,
 
     @Override
     protected void initInternal() throws LifecycleException {
-        super.initInternal();
         Container container = getContainer();
-        containerLog = container != null ? container.getLogger() : log;
+        if (container == null) {
+            throw new 
IllegalStateException(sm.getString("valveBase.noContainer"));
+        }
+        super.initInternal();
+        containerLog = container.getLogger();
     }
 
 


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to