This is an automated email from the ASF dual-hosted git repository.
rmaucher pushed a commit to branch 9.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/9.0.x by this push:
new a26f2c10c1 Improve handling for failed protocols
a26f2c10c1 is described below
commit a26f2c10c11f03fcbf7ef58a2c6653d0d86a0aa0
Author: remm <[email protected]>
AuthorDate: Wed May 20 13:26:14 2026 +0200
Improve handling for failed protocols
---
java/org/apache/catalina/connector/Connector.java | 57 ++++++++++++++++++++---
webapps/docs/changelog.xml | 4 ++
2 files changed, 54 insertions(+), 7 deletions(-)
diff --git a/java/org/apache/catalina/connector/Connector.java
b/java/org/apache/catalina/connector/Connector.java
index 013a0ee5c7..430abe2858 100644
--- a/java/org/apache/catalina/connector/Connector.java
+++ b/java/org/apache/catalina/connector/Connector.java
@@ -628,6 +628,26 @@ public class Connector extends LifecycleMBeanBase {
}
+ /**
+ * Returns the unique index for this connector.
+ * @return the index
+ */
+ public int getNameIndex() {
+ // Try shortcut that should work for nearly all uses first as it does
+ // not use reflection and is therefore faster.
+ if (protocolHandler instanceof AbstractProtocol<?>) {
+ return ((AbstractProtocol<?>) protocolHandler).getNameIndex();
+ }
+ // Fall back for custom protocol handlers not based on AbstractProtocol
+ Object index = getProperty("NameIndex");
+ if (index instanceof Integer) {
+ return ((Integer) index).intValue();
+ }
+ // Usually means an invalid protocol has been configured.
+ return 0;
+ }
+
+
/**
* Returns the port number on which this connector is configured to listen
for requests.
* The special value of 0 means select a random free port when the socket
is bound.
@@ -709,7 +729,18 @@ public class Connector extends LifecycleMBeanBase {
* @return the actual local port number
*/
public int getLocalPort() {
- return ((Integer) getProperty("localPort")).intValue();
+ // Try shortcut that should work for nearly all uses first as it does
+ // not use reflection and is therefore faster.
+ if (protocolHandler instanceof AbstractProtocol<?>) {
+ return ((AbstractProtocol<?>) protocolHandler).getLocalPort();
+ }
+ // Fall back for custom protocol handlers not based on AbstractProtocol
+ Object port = getProperty("localPort");
+ if (port instanceof Integer) {
+ return ((Integer) port).intValue();
+ }
+ // Usually means an invalid protocol has been configured.
+ return 0;
}
@@ -980,7 +1011,9 @@ public class Connector extends LifecycleMBeanBase {
* @param sslHostConfig the SSL host configuration to add
*/
public void addSslHostConfig(SSLHostConfig sslHostConfig) {
- protocolHandler.addSslHostConfig(sslHostConfig);
+ if (protocolHandler != null) {
+ protocolHandler.addSslHostConfig(sslHostConfig);
+ }
}
@@ -989,7 +1022,11 @@ public class Connector extends LifecycleMBeanBase {
* @return array of SSL host configurations
*/
public SSLHostConfig[] findSslHostConfigs() {
- return protocolHandler.findSslHostConfigs();
+ if (protocolHandler != null) {
+ return protocolHandler.findSslHostConfigs();
+ } else {
+ return new SSLHostConfig[0];
+ }
}
@@ -998,7 +1035,9 @@ public class Connector extends LifecycleMBeanBase {
* @param upgradeProtocol the upgrade protocol to add
*/
public void addUpgradeProtocol(UpgradeProtocol upgradeProtocol) {
- protocolHandler.addUpgradeProtocol(upgradeProtocol);
+ if (protocolHandler != null) {
+ protocolHandler.addUpgradeProtocol(upgradeProtocol);
+ }
}
@@ -1007,7 +1046,11 @@ public class Connector extends LifecycleMBeanBase {
* @return array of upgrade protocols
*/
public UpgradeProtocol[] findUpgradeProtocols() {
- return protocolHandler.findUpgradeProtocols();
+ if (protocolHandler != null) {
+ return protocolHandler.findUpgradeProtocols();
+ } else {
+ return new UpgradeProtocol[0];
+ }
}
@@ -1119,7 +1162,7 @@ public class Connector extends LifecycleMBeanBase {
sb.append(port);
} else {
sb.append("auto-");
- sb.append(getProperty("nameIndex"));
+ sb.append(Integer.valueOf(getNameIndex()));
}
String address = "";
if (addressObj instanceof InetAddress) {
@@ -1310,7 +1353,7 @@ public class Connector extends LifecycleMBeanBase {
sb.append(port);
} else {
sb.append("auto-");
- sb.append(getProperty("nameIndex"));
+ sb.append(Integer.valueOf(getNameIndex()));
}
}
} else {
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index 377fed979f..9e789d81fa 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -125,6 +125,10 @@
<fix>
Cleaner handling of invalid SPNEGO tokens. (remm)
</fix>
+ <fix>
+ Avoid some NPEs in the Connector class on an uninitialize protocol.
+ (remm)
+ </fix>
</changelog>
</subsection>
<subsection name="Coyote">
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]