You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2019/10/04 15:11:42 UTC

[tomcat] branch 7.0.x updated (0defa1f -> a175cad)

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

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


    from 0defa1f  Additional fix releated to BZ 63781
     new 2d3e2a4  Catch <jsp:useBean> module export issues at compile time if configured to do so
     new a175cad  Align with 8.5.x

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 java/org/apache/el/util/JreCompat.java         |  2 +-
 java/org/apache/jasper/compiler/Generator.java | 19 +++--
 java/org/apache/jasper/compiler/Localizer.java | 98 +++-----------------------
 res/checkstyle/org-import-control.xml          |  1 +
 4 files changed, 26 insertions(+), 94 deletions(-)


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


[tomcat] 01/02: Catch module export issues at compile time if configured to do so

Posted by ma...@apache.org.
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 2d3e2a423a619a219071752a74842c8427b67d15
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Fri Oct 4 00:15:26 2019 +0100

    Catch <jsp:useBean> module export issues at compile time if configured
    to do so
---
 java/org/apache/el/util/JreCompat.java         |  2 +-
 java/org/apache/jasper/compiler/Generator.java | 19 +++++++++++++------
 res/checkstyle/org-import-control.xml          |  1 +
 3 files changed, 15 insertions(+), 7 deletions(-)

diff --git a/java/org/apache/el/util/JreCompat.java b/java/org/apache/el/util/JreCompat.java
index 7ef8b87..8f226f2 100644
--- a/java/org/apache/el/util/JreCompat.java
+++ b/java/org/apache/el/util/JreCompat.java
@@ -25,7 +25,7 @@ import java.lang.reflect.AccessibleObject;
  * This class is duplicated in javax.el
  * When making changes keep the two in sync.
  */
-class JreCompat {
+public class JreCompat {
 
     private static final JreCompat instance;
 
diff --git a/java/org/apache/jasper/compiler/Generator.java b/java/org/apache/jasper/compiler/Generator.java
index 370eef7..b6de1a9 100644
--- a/java/org/apache/jasper/compiler/Generator.java
+++ b/java/org/apache/jasper/compiler/Generator.java
@@ -21,6 +21,7 @@ import java.beans.BeanInfo;
 import java.beans.IntrospectionException;
 import java.beans.Introspector;
 import java.beans.PropertyDescriptor;
+import java.lang.reflect.Constructor;
 import java.lang.reflect.Method;
 import java.lang.reflect.Modifier;
 import java.text.DateFormat;
@@ -47,6 +48,7 @@ import javax.servlet.jsp.tagext.TagInfo;
 import javax.servlet.jsp.tagext.TagVariableInfo;
 import javax.servlet.jsp.tagext.VariableInfo;
 
+import org.apache.el.util.JreCompat;
 import org.apache.jasper.Constants;
 import org.apache.jasper.JasperException;
 import org.apache.jasper.JspCompilationContext;
@@ -1284,14 +1286,19 @@ class Generator {
                     } else {
                         canonicalName = klass;
                     }
+                    // Check that there is a 0 arg constructor
+                    Constructor<?> constructor = bean.getConstructor(new Class[] {});
+                    // Check the bean is public, not an interface, not abstract
+                    // and (for Java 9+) in an exported module
                     int modifiers = bean.getModifiers();
-                    if (!Modifier.isPublic(modifiers)
-                            || Modifier.isInterface(modifiers)
-                            || Modifier.isAbstract(modifiers)) {
-                        throw new Exception("Invalid bean class modifier");
+                    JreCompat jreCompat = JreCompat.getInstance();
+                    if (!Modifier.isPublic(modifiers) ||
+                            Modifier.isInterface(modifiers) ||
+                            Modifier.isAbstract(modifiers) ||
+                            !jreCompat.canAcccess(null, constructor) ) {
+                        throw new Exception(Localizer.getMessage("jsp.error.invalid.bean",
+                                Integer.valueOf(modifiers)));
                     }
-                    // Check that there is a 0 arg constructor
-                    bean.getConstructor(new Class[] {});
                     // At compile time, we have determined that the bean class
                     // exists, with a public zero constructor, new() can be
                     // used for bean instantiation.
diff --git a/res/checkstyle/org-import-control.xml b/res/checkstyle/org-import-control.xml
index cbff820..463077b 100644
--- a/res/checkstyle/org-import-control.xml
+++ b/res/checkstyle/org-import-control.xml
@@ -92,6 +92,7 @@
   <subpackage name="jasper">
     <allow pkg="javax.el"/>
     <allow pkg="javax.servlet"/>
+    <allow pkg="org.apache.el"/>
     <allow pkg="org.apache.jasper"/>
     <allow pkg="org.apache.juli"/>
     <allow pkg="org.apache.tomcat" exact-match="true"/>


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


[tomcat] 02/02: Align with 8.5.x

Posted by ma...@apache.org.
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 a175cadf98eb83e4de5f45485f741de41221c110
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Fri Oct 4 16:09:57 2019 +0100

    Align with 8.5.x
---
 java/org/apache/jasper/compiler/Localizer.java | 98 +++-----------------------
 1 file changed, 11 insertions(+), 87 deletions(-)

diff --git a/java/org/apache/jasper/compiler/Localizer.java b/java/org/apache/jasper/compiler/Localizer.java
index d20a91c..e22803a 100644
--- a/java/org/apache/jasper/compiler/Localizer.java
+++ b/java/org/apache/jasper/compiler/Localizer.java
@@ -14,7 +14,6 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
 package org.apache.jasper.compiler;
 
 import java.text.MessageFormat;
@@ -31,15 +30,13 @@ import org.apache.jasper.runtime.ExceptionUtils;
  */
 public class Localizer {
 
-    private static ResourceBundle bundle = null;
+    private static ResourceBundle bundle;
 
     static {
         try {
-        bundle = ResourceBundle.getBundle(
-            "org.apache.jasper.resources.LocalStrings");
+            bundle = ResourceBundle.getBundle("org.apache.jasper.resources.LocalStrings");
         } catch (Throwable t) {
             ExceptionUtils.handleThrowable(t);
-            t.printStackTrace();
         }
     }
 
@@ -57,7 +54,9 @@ public class Localizer {
     public static String getMessage(String errCode) {
         String errMsg = errCode;
         try {
-            errMsg = bundle.getString(errCode);
+            if (bundle != null) {
+                errMsg = bundle.getString(errCode);
+            }
         } catch (MissingResourceException e) {
         }
         return errMsg;
@@ -71,91 +70,16 @@ public class Localizer {
      * localized error messages, it is used as the error message.
      *
      * @param errCode Error code to localize
-     * @param arg Argument for parametric replacement
-     *
-     * @return Localized error message
-     */
-    public static String getMessage(String errCode, String arg) {
-        return getMessage(errCode, new Object[] {arg});
-    }
-
-    /*
-     * Returns the localized error message corresponding to the given error
-     * code.
-     *
-     * If the given error code is not defined in the resource bundle for
-     * localized error messages, it is used as the error message.
-     *
-     * @param errCode Error code to localize
-     * @param arg1 First argument for parametric replacement
-     * @param arg2 Second argument for parametric replacement
-     *
-     * @return Localized error message
-     */
-    public static String getMessage(String errCode, String arg1, String arg2) {
-        return getMessage(errCode, new Object[] {arg1, arg2});
-    }
-
-    /*
-     * Returns the localized error message corresponding to the given error
-     * code.
-     *
-     * If the given error code is not defined in the resource bundle for
-     * localized error messages, it is used as the error message.
-     *
-     * @param errCode Error code to localize
-     * @param arg1 First argument for parametric replacement
-     * @param arg2 Second argument for parametric replacement
-     * @param arg3 Third argument for parametric replacement
-     *
-     * @return Localized error message
-     */
-    public static String getMessage(String errCode, String arg1, String arg2,
-                                    String arg3) {
-        return getMessage(errCode, new Object[] {arg1, arg2, arg3});
-    }
-
-    /*
-     * Returns the localized error message corresponding to the given error
-     * code.
-     *
-     * If the given error code is not defined in the resource bundle for
-     * localized error messages, it is used as the error message.
-     *
-     * @param errCode Error code to localize
-     * @param arg1 First argument for parametric replacement
-     * @param arg2 Second argument for parametric replacement
-     * @param arg3 Third argument for parametric replacement
-     * @param arg4 Fourth argument for parametric replacement
-     *
-     * @return Localized error message
-     */
-    public static String getMessage(String errCode, String arg1, String arg2,
-                                    String arg3, String arg4) {
-        return getMessage(errCode, new Object[] {arg1, arg2, arg3, arg4});
-    }
-
-    /*
-     * Returns the localized error message corresponding to the given error
-     * code.
-     *
-     * If the given error code is not defined in the resource bundle for
-     * localized error messages, it is used as the error message.
-     *
-     * @param errCode Error code to localize
      * @param args Arguments for parametric replacement
      *
      * @return Localized error message
      */
-    public static String getMessage(String errCode, Object[] args) {
-        String errMsg = errCode;
-        try {
-            errMsg = bundle.getString(errCode);
-            if (args != null) {
-                MessageFormat formatter = new MessageFormat(errMsg);
-                errMsg = formatter.format(args);
-            }
-        } catch (MissingResourceException e) {
+    public static String getMessage(String errCode, Object... args) {
+        String errMsg = getMessage(errCode);
+
+        if (args != null && args.length > 0) {
+            MessageFormat formatter = new MessageFormat(errMsg);
+            errMsg = formatter.format(args);
         }
 
         return errMsg;


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