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

remm pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tomcat.git


The following commit(s) were added to refs/heads/main by this push:
     new f189ef5992 Avoid unlikely NPEs and add localization
f189ef5992 is described below

commit f189ef599253c6e90bc7d4189a21a9eb85020239
Author: remm <r...@apache.org>
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 ce2f63704a..5dab3e2d16 100644
--- a/java/org/apache/jasper/resources/LocalStrings.properties
+++ b/java/org/apache/jasper/resources/LocalStrings.properties
@@ -215,6 +215,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 d061dc36a2..a503b1dac0 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 39e88e3ac6..c501cee820 100644
--- a/java/org/apache/jasper/runtime/TagHandlerPool.java
+++ b/java/org/apache/jasper/runtime/TagHandlerPool.java
@@ -21,6 +21,8 @@ import jakarta.servlet.jsp.JspException;
 import jakarta.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;
 
 /**
@@ -50,7 +52,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: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to