This is an automated email from the ASF dual-hosted git repository.
markt pushed a commit to branch 9.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/9.0.x by this push:
new 8f06ab0b94 Fix Java 21 version detection for JreCompat
8f06ab0b94 is described below
commit 8f06ab0b945e0478efef338fe54f4f9d86b592f2
Author: Mark Thomas <[email protected]>
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 75295317af..0df6e3166c 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -125,6 +125,10 @@
<code>HttpServletRequest.login(String username, String password)</code>
when the realm is configured to use GSSAPI authentication. (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: [email protected]
For additional commands, e-mail: [email protected]