This is an automated email from the ASF dual-hosted git repository.
remm 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 357a580234 Avoid unlikely NPEs and add localization
357a580234 is described below
commit 357a580234e880170e9d4c5b9bafd563fe442886
Author: remm <[email protected]>
AuthorDate: Thu Sep 21 11:35:40 2023 +0200
Avoid unlikely NPEs and add localization
Found by coverity.
---
java/org/apache/jasper/compiler/ErrorDispatcher.java | 9 ++++++++-
java/org/apache/jasper/resources/LocalStrings.properties | 1 +
java/org/apache/jasper/runtime/JspRuntimeLibrary.java | 7 ++++---
java/org/apache/jasper/runtime/TagHandlerPool.java | 4 +++-
4 files changed, 16 insertions(+), 5 deletions(-)
diff --git a/java/org/apache/jasper/compiler/ErrorDispatcher.java
b/java/org/apache/jasper/compiler/ErrorDispatcher.java
index 3b144498c9..6d3abfdf61 100644
--- a/java/org/apache/jasper/compiler/ErrorDispatcher.java
+++ b/java/org/apache/jasper/compiler/ErrorDispatcher.java
@@ -20,6 +20,7 @@ import java.io.BufferedReader;
import java.io.IOException;
import java.io.StringReader;
import java.net.MalformedURLException;
+import java.net.URL;
import java.util.ArrayList;
import java.util.List;
@@ -266,7 +267,13 @@ public class ErrorDispatcher {
if (jspcMode) {
// Get the full URL of the resource that caused the error
try {
- file = where.getURL().toString();
+ URL url = where.getURL();
+ if (url != null) {
+ file = url.toString();
+ } else {
+ // Fallback to using context-relative path
+ file = where.getFile();
+ }
} catch (MalformedURLException me) {
// Fallback to using context-relative path
file = where.getFile();
diff --git a/java/org/apache/jasper/resources/LocalStrings.properties
b/java/org/apache/jasper/resources/LocalStrings.properties
index 20675a16a5..fd5a8e020d 100644
--- a/java/org/apache/jasper/resources/LocalStrings.properties
+++ b/java/org/apache/jasper/resources/LocalStrings.properties
@@ -219,6 +219,7 @@ jsp.error.tagfile.missingPath=Path not specified to tag file
jsp.error.tagfile.nameFrom.badAttribute=The attribute directive declared at
line [{1}] with name [{0}] that matches the name-from-attribute value of this
variable directive must be of type java.lang.String, must be "required" and
must not be a "rtexprvalue".
jsp.error.tagfile.nameFrom.noAttribute=Cannot find an attribute directive with
a name [{0}] that matches the name-from-attribute value of this variable
directive
jsp.error.tagfile.nameNotUnique=The value of [{0}] and the value of [{1}] in
line [{2}] are the same.
+jsp.error.tagHandlerPool=Cannot create tag handler pool [{0}]
jsp.error.taglibDirective.absUriCannotBeResolved=The absolute uri: [{0}]
cannot be resolved in either web.xml or the jar files deployed with this
application
jsp.error.taglibDirective.both_uri_and_tagdir=Both 'uri' and 'tagdir'
attributes specified
jsp.error.taglibDirective.missing.location=Neither 'uri' nor 'tagdir'
attribute specified
diff --git a/java/org/apache/jasper/runtime/JspRuntimeLibrary.java
b/java/org/apache/jasper/runtime/JspRuntimeLibrary.java
index 5b5c1c1e3c..538f2d00ea 100644
--- a/java/org/apache/jasper/runtime/JspRuntimeLibrary.java
+++ b/java/org/apache/jasper/runtime/JspRuntimeLibrary.java
@@ -990,9 +990,10 @@ public class JspRuntimeLibrary {
String resourcePath = getContextRelativePath(request, relativePath);
RequestDispatcher rd = request.getRequestDispatcher(resourcePath);
-
- rd.include(request,
- new ServletResponseWrapperInclude(response, out));
+ if (rd != null) {
+ rd.include(request,
+ new ServletResponseWrapperInclude(response, out));
+ }
}
diff --git a/java/org/apache/jasper/runtime/TagHandlerPool.java
b/java/org/apache/jasper/runtime/TagHandlerPool.java
index c4390543c9..5f4e35cc70 100644
--- a/java/org/apache/jasper/runtime/TagHandlerPool.java
+++ b/java/org/apache/jasper/runtime/TagHandlerPool.java
@@ -21,6 +21,8 @@ import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.Tag;
import org.apache.jasper.Constants;
+import org.apache.jasper.compiler.Localizer;
+import org.apache.juli.logging.LogFactory;
import org.apache.tomcat.InstanceManager;
/**
@@ -48,7 +50,7 @@ public class TagHandlerPool {
Class<?> c = Class.forName(tpClassName);
result = (TagHandlerPool) c.getConstructor().newInstance();
} catch (Exception e) {
- e.printStackTrace();
+
LogFactory.getLog(TagHandlerPool.class).info(Localizer.getMessage("jsp.error.tagHandlerPool"),
e);
result = null;
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]