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 16:49:56 UTC

[tomcat] branch master updated (cf0ec7e -> 2fb245b)

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

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


    from cf0ec7e  Also skip interfaces reported via onStartup()
     new 40021ab  Add a module check when processing the scan for server endpoints
     new 2fb245b  Update changelog

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/tomcat/util/compat/Jre9Compat.java | 21 +++++++++++++++++++++
 java/org/apache/tomcat/util/compat/JreCompat.java  | 13 +++++++++++++
 java/org/apache/tomcat/websocket/server/WsSci.java |  9 +++++++--
 webapps/docs/changelog.xml                         |  9 +++++++++
 4 files changed, 50 insertions(+), 2 deletions(-)


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


[tomcat] 01/02: Add a module check when processing the scan for server endpoints

Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 40021ab1a249366855a4ccb8643f9c58c19a81d0
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Fri Oct 4 17:44:04 2019 +0100

    Add a module check when processing the scan for server endpoints
---
 java/org/apache/tomcat/util/compat/Jre9Compat.java | 21 +++++++++++++++++++++
 java/org/apache/tomcat/util/compat/JreCompat.java  | 13 +++++++++++++
 java/org/apache/tomcat/websocket/server/WsSci.java |  9 +++++++--
 webapps/docs/changelog.xml                         |  4 ++++
 4 files changed, 45 insertions(+), 2 deletions(-)

diff --git a/java/org/apache/tomcat/util/compat/Jre9Compat.java b/java/org/apache/tomcat/util/compat/Jre9Compat.java
index 98adc3d..29fef06 100644
--- a/java/org/apache/tomcat/util/compat/Jre9Compat.java
+++ b/java/org/apache/tomcat/util/compat/Jre9Compat.java
@@ -59,6 +59,8 @@ class Jre9Compat extends JreCompat {
     private static final Object RUNTIME_VERSION;
     private static final int RUNTIME_MAJOR_VERSION;
     private static final Method canAccessMethod;
+    private static final Method getModuleMethod;
+    private static final Method isExportedMethod;
 
     static {
         Class<?> c1 = null;
@@ -77,6 +79,8 @@ class Jre9Compat extends JreCompat {
         Object o14 = null;
         Object o15 = null;
         Method m16 = null;
+        Method m17 = null;
+        Method m18 = null;
 
         try {
             // Order is important for the error handling below.
@@ -107,6 +111,9 @@ class Jre9Compat extends JreCompat {
             o14 = runtimeVersionMethod.invoke(null);
             o15 = majorMethod.invoke(o14);
             m16 = AccessibleObject.class.getMethod("canAccess", new Class<?>[] { Object.class });
+            m17 = Class.class.getMethod("getModule");
+            Class<?> moduleClass = Class.forName("java.lang.Module");
+            m18 = moduleClass.getMethod("isExported", String.class);
 
         } catch (ClassNotFoundException e) {
             if (c1 == null) {
@@ -144,6 +151,8 @@ class Jre9Compat extends JreCompat {
         }
 
         canAccessMethod = m16;
+        getModuleMethod = m17;
+        isExportedMethod = m18;
     }
 
 
@@ -253,4 +262,16 @@ class Jre9Compat extends JreCompat {
             return false;
         }
     }
+
+
+    @Override
+    public boolean isExported(Class<?> type) {
+        try {
+            String packageName = type.getPackage().getName();
+            Object module = getModuleMethod.invoke(type);
+            return ((Boolean) isExportedMethod.invoke(module, packageName)).booleanValue();
+        } catch (ReflectiveOperationException e) {
+            return false;
+        }
+    }
 }
diff --git a/java/org/apache/tomcat/util/compat/JreCompat.java b/java/org/apache/tomcat/util/compat/JreCompat.java
index 9576fbd..b33175b 100644
--- a/java/org/apache/tomcat/util/compat/JreCompat.java
+++ b/java/org/apache/tomcat/util/compat/JreCompat.java
@@ -211,4 +211,17 @@ public class JreCompat {
         // Java 8 doesn't support modules so default to true
         return true;
     }
+
+
+    /**
+     * Is the given class in an exported package?
+     *
+     * @param type  The class to test
+     *
+     * @return Always {@code true} for Java 8. {@code true} if the enclosing
+     *         package is exported for Java 9+
+     */
+    public boolean isExported(Class<?> type) {
+        return true;
+    }
 }
diff --git a/java/org/apache/tomcat/websocket/server/WsSci.java b/java/org/apache/tomcat/websocket/server/WsSci.java
index 6f98f43..6396c60 100644
--- a/java/org/apache/tomcat/websocket/server/WsSci.java
+++ b/java/org/apache/tomcat/websocket/server/WsSci.java
@@ -31,6 +31,8 @@ import javax.websocket.server.ServerApplicationConfig;
 import javax.websocket.server.ServerEndpoint;
 import javax.websocket.server.ServerEndpointConfig;
 
+import org.apache.tomcat.util.compat.JreCompat;
+
 /**
  * Registers an interest in any class that is annotated with
  * {@link ServerEndpoint} so that Endpoint can be published via the WebSocket
@@ -60,11 +62,14 @@ public class WsSci implements ServletContainerInitializer {
             String wsPackage = ContainerProvider.class.getName();
             wsPackage = wsPackage.substring(0, wsPackage.lastIndexOf('.') + 1);
             for (Class<?> clazz : clazzes) {
+                JreCompat jreCompat = JreCompat.getInstance();
                 int modifiers = clazz.getModifiers();
                 if (!Modifier.isPublic(modifiers) ||
                         Modifier.isAbstract(modifiers) ||
-                        Modifier.isInterface(modifiers)) {
-                    // Non-public, abstract or interface - skip it.
+                        Modifier.isInterface(modifiers) ||
+                        !jreCompat.isExported(clazz)) {
+                    // Non-public, abstract, interface or not in an exported
+                    // package (Java 9+) - skip it.
                     continue;
                 }
                 // Protect against scanning the WebSocket API JARs
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index cde6e30..239241e 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -93,6 +93,10 @@
         Socket HTTP upgrade request only contains a port if a non-default port
         is being used. (markt)
       </fix>
+      <fix>
+        When running on Java 9 and above, don't attempt to instantiate WebSocket
+        Endpoints found in modules that are not exported. (markt)
+      </fix>
     </changelog>
   </subsection>
   <subsection name="Web Applications">


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


[tomcat] 02/02: Update changelog

Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 2fb245b844fc9fefaa5e0c8002a481a72c502963
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Fri Oct 4 17:49:42 2019 +0100

    Update changelog
---
 webapps/docs/changelog.xml | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index 239241e..23c8eba 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -84,6 +84,11 @@
         Add GraalVM specific ELResolver to avoid BeanInfo use in BeanElResolver
         if possible, as it needs manual reflection configuration. (remm)
       </fix>
+      <fix>
+        <bug>63781</bug>: When performing various checks related to the
+        visibility of classes, fields an methods in the EL implementation, also
+        check that the containing modeul has been exported. (markt)
+      </fix>
     </changelog>
   </subsection>
   <subsection name="Web Socket">


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