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

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


The following commit(s) were added to refs/heads/11.0.x by this push:
     new 9e1679713c Fix Java 21 version detection for JreCompat
9e1679713c is described below

commit 9e1679713c22cec7a6517382dd263e1e3c6dde8b
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Fri Feb 21 10:35:41 2025 +0000

    Fix Java 21 version detection for JreCompat
---
 java/org/apache/tomcat/util/compat/Jre21Compat.java | 15 +++++++++++----
 webapps/docs/changelog.xml                          |  4 ++++
 2 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/java/org/apache/tomcat/util/compat/Jre21Compat.java 
b/java/org/apache/tomcat/util/compat/Jre21Compat.java
index ee01f3e28e..23ebd27feb 100644
--- a/java/org/apache/tomcat/util/compat/Jre21Compat.java
+++ b/java/org/apache/tomcat/util/compat/Jre21Compat.java
@@ -32,6 +32,7 @@ public class Jre21Compat extends Jre19Compat {
     private static final Log log = LogFactory.getLog(Jre21Compat.class);
     private static final StringManager sm = 
StringManager.getManager(Jre21Compat.class);
 
+    private static final boolean supported;
     private static final Method nameMethod;
     private static final Method startMethod;
     private static final Method ofVirtualMethod;
@@ -46,9 +47,14 @@ public class Jre21Compat extends Jre19Compat {
         Method m4 = null;
 
         try {
-            c1 = Class.forName("java.lang.Thread$Builder");
-            m1 = c1.getMethod("name", String.class, long.class);
-            m2 = c1.getMethod("start", Runnable.class);
+            // Note: Virtual threads is the main new feature in Java 21, but 
it was previously
+            // present as a preview. As a result, it is more accurate to test 
for another
+            // new class
+            c1 = Class.forName("java.util.SequencedCollection");
+
+            Class<?> c2 = Class.forName("java.lang.Thread$Builder");
+            m1 = c2.getMethod("name", String.class, long.class);
+            m2 = c2.getMethod("start", Runnable.class);
             m3 = Thread.class.getMethod("ofVirtual", (Class<?>[]) null);
             m4 = Subject.class.getMethod("callAs", Subject.class, 
Callable.class);
         } catch (ClassNotFoundException e) {
@@ -58,6 +64,7 @@ public class Jre21Compat extends Jre19Compat {
             // Should never happen
             log.error(sm.getString("jre21Compat.unexpected"), e);
         }
+        supported = (c1 != null);
         nameMethod = m1;
         startMethod = m2;
         ofVirtualMethod = m3;
@@ -65,7 +72,7 @@ public class Jre21Compat extends Jre19Compat {
     }
 
     static boolean isSupported() {
-        return ofVirtualMethod != null;
+        return supported;
     }
 
     @Override
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index 72776636af..24b96e60b5 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -129,6 +129,10 @@
         Improve the checks for exposure to and protection against 
CVE-2024-56337
         so that reflection is not used unless required. (markt)
       </fix>
+      <fix>
+        Fix a bug in the JRE compatibility detection that incorrectly 
identified
+        Java 19 and Java 20 as supporting Java 21 features. (markt)
+      </fix>
     </changelog>
   </subsection>
   <subsection name="Coyote">


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

Reply via email to