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

markt pushed a commit to branch 7.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git

commit 7de970e4e37ac6124453759fb1a1a8b4273ed6be
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Thu Nov 14 11:23:39 2019 +0000

    More SpotBugs fixes and associated alignment with 8.5.x/9.0.x
---
 .../apache/jasper/compiler/JspRuntimeContext.java  |  7 +++--
 .../jasper/resources/LocalStrings.properties       |  1 +
 .../jasper/resources/LocalStrings_fr.properties    |  1 +
 .../jasper/resources/LocalStrings_ja.properties    |  1 +
 .../jasper/resources/LocalStrings_ko.properties    |  1 +
 .../apache/jasper/servlet/JspServletWrapper.java   | 30 ++++++++++++----------
 java/org/apache/juli/logging/LogFactory.java       | 22 ++++++++++------
 .../apache/tomcat/buildutil/translate/Utils.java   |  6 ++++-
 8 files changed, 45 insertions(+), 24 deletions(-)

diff --git a/java/org/apache/jasper/compiler/JspRuntimeContext.java 
b/java/org/apache/jasper/compiler/JspRuntimeContext.java
index 792f398..13f4a24 100644
--- a/java/org/apache/jasper/compiler/JspRuntimeContext.java
+++ b/java/org/apache/jasper/compiler/JspRuntimeContext.java
@@ -19,6 +19,7 @@ package org.apache.jasper.compiler;
 import java.io.File;
 import java.io.FileNotFoundException;
 import java.io.FilePermission;
+import java.io.IOException;
 import java.net.URL;
 import java.net.URLClassLoader;
 import java.security.CodeSource;
@@ -606,8 +607,10 @@ public final class JspRuntimeContext {
                         permissions.add(
                                 new FilePermission(jndiUrl,"read") );
                 }
-            } catch(Exception e) {
-                context.log("Security Init for context failed",e);
+            } catch (IOException e) {
+                context.log(Localizer.getMessage("jsp.error.security"), e);
+            } catch (RuntimeException e) {
+                context.log(Localizer.getMessage("jsp.error.security"), e);
             }
         }
         return new SecurityHolder(source, permissions);
diff --git a/java/org/apache/jasper/resources/LocalStrings.properties 
b/java/org/apache/jasper/resources/LocalStrings.properties
index f63d840..5c6d87b 100644
--- a/java/org/apache/jasper/resources/LocalStrings.properties
+++ b/java/org/apache/jasper/resources/LocalStrings.properties
@@ -173,6 +173,7 @@ jsp.error.prolog_config_encoding_mismatch=Page-encoding 
specified in XML prolog
 jsp.error.prolog_pagedir_encoding_mismatch=Page-encoding specified in XML 
prolog [{0}] is different from that specified in page directive [{1}]
 jsp.error.quotes.unterminated=Unterminated quotes
 jsp.error.scripting.variable.missing_name=Unable to determine scripting 
variable name from attribute [{0}]
+jsp.error.security=Security initialization failed for context
 jsp.error.servlet.destroy.failed=Exception during Servlet.destroy() for JSP 
page
 jsp.error.setLastModified=Unable to set last modified date for file [{0}]
 jsp.error.signature.classnotfound=The class [{0}] specified in the method 
signature in TLD for the function [{1}] cannot be found. [{2}]
diff --git a/java/org/apache/jasper/resources/LocalStrings_fr.properties 
b/java/org/apache/jasper/resources/LocalStrings_fr.properties
index e1fb996..c448801 100644
--- a/java/org/apache/jasper/resources/LocalStrings_fr.properties
+++ b/java/org/apache/jasper/resources/LocalStrings_fr.properties
@@ -171,6 +171,7 @@ jsp.error.prolog_config_encoding_mismatch=Le page-encoding 
spécifié dans le pr
 jsp.error.prolog_pagedir_encoding_mismatch=L''encodage spécifié dans le 
prologue XML [{0}] est différent de celui spécifié dans la directive de page 
[{1}]
 jsp.error.quotes.unterminated=Guillemets non terminés
 jsp.error.scripting.variable.missing_name=Incapable de déterminer le nom de 
variable scripting d''après l''attribut [{0}]
+jsp.error.security=L'initialisation de la sécurité a échouée pour le contexte
 jsp.error.servlet.destroy.failed=Erreur pendant le Servlet.destroy() de la 
page JSP
 jsp.error.setLastModified=Impossible de fixer la date de dernière modification 
pour le fichier [{0}]
 jsp.error.signature.classnotfound=La classe [{0}] spećifié dans la signature 
de la méthode dans la TLD pour la fonction [{1}] n''a pas pu être trouvée [{2}]
diff --git a/java/org/apache/jasper/resources/LocalStrings_ja.properties 
b/java/org/apache/jasper/resources/LocalStrings_ja.properties
index a495143..0924af7 100644
--- a/java/org/apache/jasper/resources/LocalStrings_ja.properties
+++ b/java/org/apache/jasper/resources/LocalStrings_ja.properties
@@ -173,6 +173,7 @@ 
jsp.error.prolog_config_encoding_mismatch=XML導入部で指定されたpage-enc
 jsp.error.prolog_pagedir_encoding_mismatch=XML導入部で指定されたpage-encoding [{0}] 
がpage指示子中の指定 [{1}] と違います
 jsp.error.quotes.unterminated=引用符が終了していません
 jsp.error.scripting.variable.missing_name=属性 [{0}] からスクリプト変数名を決定できません
+jsp.error.security=コンテキストのセキュリティの初期化に失敗しました。
 jsp.error.servlet.destroy.failed=JSPページのServlet.destroy()の例外
 jsp.error.setLastModified=ファイル[{0}]の最終更新日を設定できません
 jsp.error.signature.classnotfound=TLDの中のメソッドシグネチャで関数 [{1}] に指定されているクラス [{0}] 
が見つかりません。 [{2}]
diff --git a/java/org/apache/jasper/resources/LocalStrings_ko.properties 
b/java/org/apache/jasper/resources/LocalStrings_ko.properties
index 17139f7..1968db5 100644
--- a/java/org/apache/jasper/resources/LocalStrings_ko.properties
+++ b/java/org/apache/jasper/resources/LocalStrings_ko.properties
@@ -166,6 +166,7 @@ jsp.error.prolog_config_encoding_mismatch=XML 프롤로그 [{0}]에 
지정된 
 jsp.error.prolog_pagedir_encoding_mismatch=XML 프롤로그 [{0}]에 지정된 페이지 인코딩이, 페이지 
지시어 [{1}]에 지정된 것과 다릅니다.
 jsp.error.quotes.unterminated=종료되지 않은 인용부들
 jsp.error.scripting.variable.missing_name=속성 [{0}](으)로부터 스크립팅 변수 이름을 결정할 수 
없습니다.
+jsp.error.security=컨텍스트를 위한 보안 초기화 작업이 실패했습니다.
 jsp.error.servlet.destroy.failed=JSP 페이지를 위한 Servlet.destroy() 호출 중 예외 발생
 jsp.error.setLastModified=파일 [{0}]의 최종 변경 시간을 설정할 수 없습니다.
 jsp.error.signature.classnotfound=TLD 내에 function [{1}]을 위해 지정된 메소드 signature에 
포함된 클래스 [{0}]을(를) 찾을 수 없습니다. [{2}]
diff --git a/java/org/apache/jasper/servlet/JspServletWrapper.java 
b/java/org/apache/jasper/servlet/JspServletWrapper.java
index fe6b454..5bd657e 100644
--- a/java/org/apache/jasper/servlet/JspServletWrapper.java
+++ b/java/org/apache/jasper/servlet/JspServletWrapper.java
@@ -72,7 +72,7 @@ import org.apache.tomcat.InstanceManager;
 public class JspServletWrapper {
 
     private static final Map<String,Long> ALWAYS_OUTDATED_DEPENDENCIES =
-        new HashMap<String,Long>();
+            new HashMap<String,Long>();
 
     static {
         // If this is missing,
@@ -82,13 +82,13 @@ public class JspServletWrapper {
     // Logger
     private final Log log = LogFactory.getLog(JspServletWrapper.class); // 
must not be static
 
-    private Servlet theServlet;
-    private String jspUri;
-    private Class<?> tagHandlerClass;
-    private JspCompilationContext ctxt;
+    private volatile Servlet theServlet;
+    private final String jspUri;
+    private volatile Class<?> tagHandlerClass;
+    private final JspCompilationContext ctxt;
     private long available = 0L;
-    private ServletConfig config;
-    private Options options;
+    private final ServletConfig config;
+    private final Options options;
     /*
      * The servlet / tag file needs a compilation check on first access. Use a
      * separate flag (rather then theServlet == null / tagHandlerClass == null
@@ -99,7 +99,7 @@ public class JspServletWrapper {
     private volatile boolean mustCompile = true;
     /* Whether the servlet/tag file needs reloading on next access */
     private volatile boolean reload = true;
-    private boolean isTagFile;
+    private final boolean isTagFile;
     private int tripCount;
     private JasperException compileException;
     /* Timestamp of last time servlet resource was modified */
@@ -254,7 +254,9 @@ public class JspServletWrapper {
     }
 
     /**
-     * Compile (if needed) and load a tag file
+     * Compile (if needed) and load a tag file.
+     * @return the loaded class
+     * @throws JasperException Error compiling or loading tag file
      */
     public Class<?> loadTagFile() throws JasperException {
 
@@ -296,6 +298,8 @@ public class JspServletWrapper {
      * when compiling tag files with circular dependencies.  A prototype
      * (skeleton) with no dependencies on other other tag files is
      * generated and compiled.
+     * @return the loaded class
+     * @throws JasperException Error compiling or loading tag file
      */
     public Class<?> loadTagFilePrototype() throws JasperException {
 
@@ -309,6 +313,7 @@ public class JspServletWrapper {
 
     /**
      * Get a list of files that the current page has source dependency on.
+     * @return the map of dependent resources
      */
     public java.util.Map<String,Long> getDependants() {
         try {
@@ -322,11 +327,11 @@ public class JspServletWrapper {
                         }
                     }
                 }
-                target = tagHandlerClass.newInstance();
+                target = tagHandlerClass.getConstructor().newInstance();
             } else {
                 target = getServlet();
             }
-            if (target != null && target instanceof JspSourceDependent) {
+            if (target instanceof JspSourceDependent) {
                 return ((JspSourceDependent) target).getDependants();
             }
         } catch (AbstractMethodError ame) {
@@ -439,7 +444,6 @@ public class JspServletWrapper {
         }
 
         try {
-
             /*
              * (3) Handle limitation of number of loaded Jsps
              */
@@ -459,6 +463,7 @@ public class JspServletWrapper {
                     }
                 }
             }
+
             /*
              * (4) Service request
              */
@@ -630,5 +635,4 @@ public class JspServletWrapper {
             return new JasperException(ex);
         }
     }
-
 }
diff --git a/java/org/apache/juli/logging/LogFactory.java 
b/java/org/apache/juli/logging/LogFactory.java
index 14b66e8..9e4926f 100644
--- a/java/org/apache/juli/logging/LogFactory.java
+++ b/java/org/apache/juli/logging/LogFactory.java
@@ -188,11 +188,12 @@ public class LogFactory {
      *  returned (the meaning of this name is only known to the underlying
      *  logging implementation that is being wrapped)
      *
+     * @return A log instance with the requested name
+     *
      * @exception LogConfigurationException if a suitable <code>Log</code>
      *  instance cannot be returned
      */
-    public Log getInstance(String name)
-        throws LogConfigurationException {
+    public Log getInstance(String name) throws LogConfigurationException {
         return DirectJDKLog.getInstance(name);
     }
 
@@ -260,11 +261,12 @@ public class LogFactory {
      *
      * @param clazz Class for which a suitable Log name will be derived
      *
+     * @return A log instance with a name of clazz.getName()
+     *
      * @exception LogConfigurationException if a suitable <code>Log</code>
      *  instance cannot be returned
      */
-    public Log getInstance(Class<?> clazz)
-        throws LogConfigurationException {
+    public Log getInstance(Class<?> clazz) throws LogConfigurationException {
         return getInstance( clazz.getName());
     }
 
@@ -297,6 +299,8 @@ public class LogFactory {
      * properties defined in this file will be set as configuration attributes
      * on the corresponding <code>LogFactory</code> instance.</p>
      *
+     * @return The singleton LogFactory instance
+     *
      * @exception LogConfigurationException if the implementation class is not
      *  available or cannot be instantiated.
      */
@@ -311,13 +315,14 @@ public class LogFactory {
      *
      * @param clazz Class from which a log name will be derived
      *
+     * @return A log instance with a name of clazz.getName()
+     *
      * @exception LogConfigurationException if a suitable <code>Log</code>
      *  instance cannot be returned
      */
     public static Log getLog(Class<?> clazz)
         throws LogConfigurationException {
-        return (getFactory().getInstance(clazz));
-
+        return getFactory().getInstance(clazz);
     }
 
 
@@ -329,13 +334,14 @@ public class LogFactory {
      *  returned (the meaning of this name is only known to the underlying
      *  logging implementation that is being wrapped)
      *
+     * @return A log instance with the requested name
+     *
      * @exception LogConfigurationException if a suitable <code>Log</code>
      *  instance cannot be returned
      */
     public static Log getLog(String name)
         throws LogConfigurationException {
-        return (getFactory().getInstance(name));
-
+        return getFactory().getInstance(name);
     }
 
 
diff --git a/java/org/apache/tomcat/buildutil/translate/Utils.java 
b/java/org/apache/tomcat/buildutil/translate/Utils.java
index 50ea4ed..ef731e2 100644
--- a/java/org/apache/tomcat/buildutil/translate/Utils.java
+++ b/java/org/apache/tomcat/buildutil/translate/Utils.java
@@ -95,7 +95,11 @@ public class Utils {
 
 
     static void processDirectory(File root, File dir, Map<String,Properties> 
translations) throws IOException {
-        for (File f : dir.listFiles()) {
+        File[] files = dir.listFiles();
+        if (files == null) {
+            throw new IllegalArgumentException("Not a directory [" + 
dir.getAbsolutePath() + "]");
+        }
+        for (File f : files) {
             if (f.isDirectory()) {
                 processDirectory(root, f, translations);
             } else if (f.isFile()) {


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to