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

markt-asf 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 f4aaacfe31 Review Return null from ResourceLinkFactory when the global 
naming..."
f4aaacfe31 is described below

commit f4aaacfe31cca9485e3c9c10dd4bfc210920e690
Author: Mark Thomas <[email protected]>
AuthorDate: Fri Nov 6 18:46:19 2026 +0000

    Review Return null from ResourceLinkFactory when the global naming..."
    
    Fix double read of global context
---
 java/org/apache/naming/factory/ResourceLinkFactory.java | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/java/org/apache/naming/factory/ResourceLinkFactory.java 
b/java/org/apache/naming/factory/ResourceLinkFactory.java
index 4a959fcc27..2925b0b35d 100644
--- a/java/org/apache/naming/factory/ResourceLinkFactory.java
+++ b/java/org/apache/naming/factory/ResourceLinkFactory.java
@@ -181,11 +181,13 @@ public class ResourceLinkFactory implements ObjectFactory 
{
             // The global context may be missing if the web application was
             // registered before the server created its naming context, which
             // can happen with embedded start-up ordering
-            if (globalContext == null) {
+            // Read the field once so that a concurrent change cannot lead to 
a null being dereferenced
+            Context global = globalContext;
+            if (global == null) {
                 log.warn(sm.getString("resourceLinkFactory.noGlobalContext", 
globalName));
                 return null;
             }
-            Object result = globalContext.lookup(globalName);
+            Object result = global.lookup(globalName);
             if (result == null) {
                 return null;
             }


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

Reply via email to