This is an automated email from the ASF dual-hosted git repository.
rmaucher 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 7fc143fcc5 Minor naming fixes from code review
7fc143fcc5 is described below
commit 7fc143fcc5eb8daadfc00548ef834d0486547073
Author: remm <[email protected]>
AuthorDate: Mon Jun 1 16:51:14 2026 +0200
Minor naming fixes from code review
---
java/org/apache/naming/NamingContext.java | 16 ++++--
.../naming/NamingContextBindingsEnumeration.java | 2 +-
.../apache/naming/NamingContextEnumeration.java | 2 +-
java/org/apache/naming/ServiceRef.java | 16 +++---
.../apache/naming/factory/MailSessionFactory.java | 5 +-
.../apache/naming/factory/ResourceLinkFactory.java | 6 +-
.../org/apache/naming/factory/SendMailFactory.java | 65 +++++++++++-----------
7 files changed, 63 insertions(+), 49 deletions(-)
diff --git a/java/org/apache/naming/NamingContext.java
b/java/org/apache/naming/NamingContext.java
index ee943ef8d3..7f680a43d3 100644
--- a/java/org/apache/naming/NamingContext.java
+++ b/java/org/apache/naming/NamingContext.java
@@ -384,13 +384,17 @@ public class NamingContext implements Context {
return nameParser;
}
+ NamingEntry entry = bindings.get(name.get(0));
+ if (entry == null) {
+ throw new
NameNotFoundException(sm.getString("namingContext.nameNotBound", name,
name.get(0)));
+ }
+
+ if (entry.type != NamingEntry.CONTEXT) {
+ throw new
NotContextException(sm.getString("namingContext.contextExpected", name.get(0)));
+ }
+
if (name.size() > 1) {
- Object obj = bindings.get(name.get(0));
- if (obj instanceof Context) {
- return ((Context) obj).getNameParser(name.getSuffix(1));
- } else {
- throw new
NotContextException(sm.getString("namingContext.contextExpected", name.get(0)));
- }
+ return ((Context) entry.value).getNameParser(name.getSuffix(1));
}
return nameParser;
diff --git a/java/org/apache/naming/NamingContextBindingsEnumeration.java
b/java/org/apache/naming/NamingContextBindingsEnumeration.java
index e462f5249a..0c505b7926 100644
--- a/java/org/apache/naming/NamingContextBindingsEnumeration.java
+++ b/java/org/apache/naming/NamingContextBindingsEnumeration.java
@@ -113,7 +113,7 @@ public class NamingContextBindingsEnumeration implements
NamingEnumeration<Bindi
value = entry.value;
}
- return new Binding(entry.name, value.getClass().getName(), value,
true);
+ return new Binding(entry.name, value == null ? null :
value.getClass().getName(), value, true);
}
}
diff --git a/java/org/apache/naming/NamingContextEnumeration.java
b/java/org/apache/naming/NamingContextEnumeration.java
index 16cc66231d..fa81277ebc 100644
--- a/java/org/apache/naming/NamingContextEnumeration.java
+++ b/java/org/apache/naming/NamingContextEnumeration.java
@@ -79,7 +79,7 @@ public class NamingContextEnumeration implements
NamingEnumeration<NameClassPair
@Override
public NameClassPair nextElement() {
NamingEntry entry = iterator.next();
- return new NameClassPair(entry.name, entry.value.getClass().getName());
+ return new NameClassPair(entry.name, entry.value == null ? null :
entry.value.getClass().getName());
}
diff --git a/java/org/apache/naming/ServiceRef.java
b/java/org/apache/naming/ServiceRef.java
index e72bfce544..f12387b653 100644
--- a/java/org/apache/naming/ServiceRef.java
+++ b/java/org/apache/naming/ServiceRef.java
@@ -118,13 +118,15 @@ public class ServiceRef extends AbstractRef {
refAddr = new StringRefAddr(SERVICE_INTERFACE, serviceInterface);
add(refAddr);
}
- if (serviceQname[0] != null) {
- refAddr = new StringRefAddr(SERVICE_NAMESPACE, serviceQname[0]);
- add(refAddr);
- }
- if (serviceQname[1] != null) {
- refAddr = new StringRefAddr(SERVICE_LOCAL_PART, serviceQname[1]);
- add(refAddr);
+ if (serviceQname != null) {
+ if (serviceQname.length > 0 && serviceQname[0] != null) {
+ refAddr = new StringRefAddr(SERVICE_NAMESPACE,
serviceQname[0]);
+ add(refAddr);
+ }
+ if (serviceQname.length > 1 && serviceQname[1] != null) {
+ refAddr = new StringRefAddr(SERVICE_LOCAL_PART,
serviceQname[1]);
+ add(refAddr);
+ }
}
if (wsdl != null) {
refAddr = new StringRefAddr(WSDL, wsdl);
diff --git a/java/org/apache/naming/factory/MailSessionFactory.java
b/java/org/apache/naming/factory/MailSessionFactory.java
index b8ccae0b0f..e554ec2ff9 100644
--- a/java/org/apache/naming/factory/MailSessionFactory.java
+++ b/java/org/apache/naming/factory/MailSessionFactory.java
@@ -70,8 +70,10 @@ public class MailSessionFactory implements ObjectFactory {
@Override
public Object getObjectInstance(Object refObj, Name name, Context context,
Hashtable<?,?> env) throws Exception {
+ if (!(refObj instanceof Reference ref)) {
+ return null;
+ }
// Return null if we cannot create an object of the requested type
- final Reference ref = (Reference) refObj;
if (!ref.getClassName().equals(factoryType)) {
return null;
}
@@ -118,5 +120,6 @@ public class MailSessionFactory implements ObjectFactory {
// Create and return the new Session object
return Session.getInstance(props, auth);
+
}
}
diff --git a/java/org/apache/naming/factory/ResourceLinkFactory.java
b/java/org/apache/naming/factory/ResourceLinkFactory.java
index bc85cb7bca..aa6d4d2d04 100644
--- a/java/org/apache/naming/factory/ResourceLinkFactory.java
+++ b/java/org/apache/naming/factory/ResourceLinkFactory.java
@@ -16,7 +16,6 @@
*/
package org.apache.naming.factory;
-import java.util.HashMap;
import java.util.Hashtable;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
@@ -80,7 +79,7 @@ public class ResourceLinkFactory implements ObjectFactory {
ClassLoader cl = Thread.currentThread().getContextClassLoader();
// Web application initialization is single threaded so this is
// safe.
- globalResourceRegistrations.computeIfAbsent(cl, k -> new
HashMap<>()).put(localName, globalName);
+ globalResourceRegistrations.computeIfAbsent(cl, k -> new
ConcurrentHashMap<>()).put(localName, globalName);
}
@@ -166,6 +165,9 @@ public class ResourceLinkFactory implements ObjectFactory {
return null;
}
Object result = globalContext.lookup(globalName);
+ if (result == null) {
+ return null;
+ }
// Check the expected type
String expectedClassName = ref.getClassName();
if (expectedClassName == null) {
diff --git a/java/org/apache/naming/factory/SendMailFactory.java
b/java/org/apache/naming/factory/SendMailFactory.java
index 0415fba14b..1a8a1be8ca 100644
--- a/java/org/apache/naming/factory/SendMailFactory.java
+++ b/java/org/apache/naming/factory/SendMailFactory.java
@@ -79,42 +79,45 @@ public class SendMailFactory implements ObjectFactory {
*/
@Override
public Object getObjectInstance(Object refObj, Name name, Context ctx,
Hashtable<?,?> env) throws Exception {
- final Reference ref = (Reference) refObj;
- if (ref.getClassName().equals(DataSourceClassName)) {
- // set up the smtp session that will send the message
- Properties props = new Properties();
- // enumeration of all refaddr
- Enumeration<RefAddr> list = ref.getAll();
- // current refaddr to be set
- RefAddr refaddr;
- // set transport to smtp
- props.put("mail.transport.protocol", "smtp");
+ if (!(refObj instanceof Reference ref)) {
+ return null;
+ }
+ if (!ref.getClassName().equals(DataSourceClassName)) {
+ return null;
+ }
- while (list.hasMoreElements()) {
- refaddr = list.nextElement();
+ // set up the smtp session that will send the message
+ Properties props = new Properties();
+ // enumeration of all refaddr
+ Enumeration<RefAddr> list = ref.getAll();
+ // current refaddr to be set
+ RefAddr refaddr;
+ // set transport to smtp
+ props.put("mail.transport.protocol", "smtp");
- // set property
- props.put(refaddr.getType(), refaddr.getContent());
+ while (list.hasMoreElements()) {
+ refaddr = list.nextElement();
+
+ // set property
+ props.put(refaddr.getType(), refaddr.getContent());
+ }
+ MimeMessage message = new MimeMessage(Session.getInstance(props));
+ try {
+ RefAddr fromAddr = ref.get("mail.from");
+ String from = null;
+ if (fromAddr != null) {
+ from = (String) fromAddr.getContent();
}
- MimeMessage message = new MimeMessage(Session.getInstance(props));
- try {
- RefAddr fromAddr = ref.get("mail.from");
- String from = null;
- if (fromAddr != null) {
- from = (String) fromAddr.getContent();
- }
- if (from != null) {
- message.setFrom(new InternetAddress(from));
- }
- message.setSubject("");
- } catch (Throwable t) {
- ExceptionUtils.handleThrowable(t);
- // Otherwise ignore
+ if (from != null) {
+ message.setFrom(new InternetAddress(from));
}
- return new MimePartDataSource(message);
- } else { // We can't create an instance of the DataSource
- return null;
+ message.setSubject("");
+ } catch (Throwable t) {
+ ExceptionUtils.handleThrowable(t);
+ // Otherwise ignore
}
+ return new MimePartDataSource(message);
+
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]