This is an automated email from the ASF dual-hosted git repository.
remm pushed a commit to branch 8.5.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/8.5.x by this push:
new daaa6edc4e Fix various possible NPEs
daaa6edc4e is described below
commit daaa6edc4e74192cd2659ac0e1f7193931cbfcb3
Author: remm <[email protected]>
AuthorDate: Wed Sep 13 16:25:57 2023 +0200
Fix various possible NPEs
Found by Coverity.
---
.../catalina/storeconfig/StandardContextSF.java | 2 +-
.../apache/catalina/storeconfig/StoreConfig.java | 28 +++++++++++++++++-----
.../catalina/storeconfig/StoreContextAppender.java | 4 +++-
.../catalina/storeconfig/StoreFactoryBase.java | 9 +++++--
4 files changed, 33 insertions(+), 10 deletions(-)
diff --git a/java/org/apache/catalina/storeconfig/StandardContextSF.java
b/java/org/apache/catalina/storeconfig/StandardContextSF.java
index 1da9ee31e9..b761c9bf6b 100644
--- a/java/org/apache/catalina/storeconfig/StandardContextSF.java
+++ b/java/org/apache/catalina/storeconfig/StandardContextSF.java
@@ -71,7 +71,7 @@ public class StandardContextSF extends StoreFactoryBase {
if (aContext instanceof StandardContext) {
StoreDescription desc = getRegistry().findDescription(
aContext.getClass());
- if (desc.isStoreSeparate()) {
+ if (desc != null && desc.isStoreSeparate()) {
URL configFile = ((StandardContext) aContext)
.getConfigFile();
if (configFile != null) {
diff --git a/java/org/apache/catalina/storeconfig/StoreConfig.java
b/java/org/apache/catalina/storeconfig/StoreConfig.java
index 4e0044b400..b06b7dbe6e 100644
--- a/java/org/apache/catalina/storeconfig/StoreConfig.java
+++ b/java/org/apache/catalina/storeconfig/StoreConfig.java
@@ -290,12 +290,16 @@ public class StoreConfig implements IStoreConfig {
StoreDescription desc = null;
try {
desc = getRegistry().findDescription(aContext.getClass());
- oldSeparate = desc.isStoreSeparate();
- desc.setStoreSeparate(false);
- desc.getStoreFactory().store(aWriter, indent, aContext);
+ if (desc != null) {
+ oldSeparate = desc.isStoreSeparate();
+ desc.setStoreSeparate(false);
+ desc.getStoreFactory().store(aWriter, indent, aContext);
+ }
} finally {
if (desc != null) {
desc.setStoreSeparate(oldSeparate);
+ } else {
+ log.warn(sm.getString("factory.storeNoDescriptor",
aContext.getClass()));
}
}
}
@@ -309,7 +313,11 @@ public class StoreConfig implements IStoreConfig {
throws Exception {
StoreDescription desc = getRegistry().findDescription(
aHost.getClass());
- desc.getStoreFactory().store(aWriter, indent, aHost);
+ if (desc != null) {
+ desc.getStoreFactory().store(aWriter, indent, aHost);
+ } else {
+ log.warn(sm.getString("factory.storeNoDescriptor",
aHost.getClass()));
+ }
}
/**
@@ -321,7 +329,11 @@ public class StoreConfig implements IStoreConfig {
Service aService) throws Exception {
StoreDescription desc = getRegistry().findDescription(
aService.getClass());
- desc.getStoreFactory().store(aWriter, indent, aService);
+ if (desc != null) {
+ desc.getStoreFactory().store(aWriter, indent, aService);
+ } else {
+ log.warn(sm.getString("factory.storeNoDescriptor",
aService.getClass()));
+ }
}
/**
@@ -333,7 +345,11 @@ public class StoreConfig implements IStoreConfig {
Server aServer) throws Exception {
StoreDescription desc = getRegistry().findDescription(
aServer.getClass());
- desc.getStoreFactory().store(writer, indent, aServer);
+ if (desc != null) {
+ desc.getStoreFactory().store(writer, indent, aServer);
+ } else {
+ log.warn(sm.getString("factory.storeNoDescriptor",
aServer.getClass()));
+ }
}
}
diff --git a/java/org/apache/catalina/storeconfig/StoreContextAppender.java
b/java/org/apache/catalina/storeconfig/StoreContextAppender.java
index 920a482152..d266f9eac2 100644
--- a/java/org/apache/catalina/storeconfig/StoreContextAppender.java
+++ b/java/org/apache/catalina/storeconfig/StoreContextAppender.java
@@ -65,7 +65,9 @@ public class StoreContextAppender extends StoreAppender {
StandardContext context = ((StandardContext) bean);
if ("workDir".equals(attrName)) {
String defaultWorkDir = getDefaultWorkDir(context);
- isPrint = !defaultWorkDir.equals(context.getWorkDir());
+ if (defaultWorkDir != null) {
+ isPrint = !defaultWorkDir.equals(context.getWorkDir());
+ }
} else if ("path".equals(attrName)) {
isPrint = desc.isStoreSeparate()
&& desc.isExternalAllowed()
diff --git a/java/org/apache/catalina/storeconfig/StoreFactoryBase.java
b/java/org/apache/catalina/storeconfig/StoreFactoryBase.java
index 7003519470..4ca991c589 100644
--- a/java/org/apache/catalina/storeconfig/StoreFactoryBase.java
+++ b/java/org/apache/catalina/storeconfig/StoreFactoryBase.java
@@ -167,8 +167,13 @@ public class StoreFactoryBase implements IStoreFactory {
if (elementFactory != null) {
StoreDescription desc = getRegistry().findDescription(
aTagElement.getClass());
- if (!desc.isTransientChild(aTagElement.getClass().getName())) {
- elementFactory.store(aWriter, indent, aTagElement);
+ if (desc != null) {
+ if
(!desc.isTransientChild(aTagElement.getClass().getName())) {
+ elementFactory.store(aWriter, indent, aTagElement);
+ }
+ } else {
+ log.warn(sm.getString("factory.storeNoDescriptor",
aTagElement
+ .getClass()));
}
} else {
log.warn(sm.getString("factory.storeNoDescriptor", aTagElement
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]