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

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


The following commit(s) were added to refs/heads/11.0.x by this push:
     new df2c2a9733 Re-work null check
df2c2a9733 is described below

commit df2c2a97335eabd1e1b946fbaaa9c50c1d51223e
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 |  2 ++
 java/org/apache/catalina/valves/ValveBase.java          | 10 +++++-----
 2 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/java/org/apache/catalina/valves/LocalStrings.properties 
b/java/org/apache/catalina/valves/LocalStrings.properties
index f9ce6b919e..8e486bb94d 100644
--- a/java/org/apache/catalina/valves/LocalStrings.properties
+++ b/java/org/apache/catalina/valves/LocalStrings.properties
@@ -179,3 +179,5 @@ stuckThreadDetectionValve.interrupted=Thread interrupted 
after the request is fi
 stuckThreadDetectionValve.notifyStuckThreadCompleted=Thread [{0}] (id=[{3}]) 
was previously reported to be stuck but has completed. It was active for 
approximately [{1}] milliseconds.{2,choice,0#|0< There is/are still [{2}] 
thread(s) that are monitored by this Valve and may be stuck.}
 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