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

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


The following commit(s) were added to refs/heads/main by this push:
     new 13be7d0668 Add Java 24 detection to JreCompat
13be7d0668 is described below

commit 13be7d06688a6914076fadf085056ff342c46220
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Fri Jan 17 17:38:27 2025 +0000

    Add Java 24 detection to JreCompat
---
 .../org/apache/tomcat/util/compat/Jre24Compat.java | 49 ++++++++++++++++++++++
 java/org/apache/tomcat/util/compat/JreCompat.java  | 14 ++++++-
 .../tomcat/util/compat/LocalStrings.properties     |  2 +
 3 files changed, 64 insertions(+), 1 deletion(-)

diff --git a/java/org/apache/tomcat/util/compat/Jre24Compat.java 
b/java/org/apache/tomcat/util/compat/Jre24Compat.java
new file mode 100644
index 0000000000..07fcd5c93b
--- /dev/null
+++ b/java/org/apache/tomcat/util/compat/Jre24Compat.java
@@ -0,0 +1,49 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.tomcat.util.compat;
+
+import java.lang.reflect.Method;
+import java.time.Duration;
+
+import org.apache.juli.logging.Log;
+import org.apache.juli.logging.LogFactory;
+import org.apache.tomcat.util.res.StringManager;
+
+public class Jre24Compat extends Jre22Compat {
+
+    private static final Log log = LogFactory.getLog(Jre24Compat.class);
+    private static final StringManager sm = 
StringManager.getManager(Jre24Compat.class);
+
+    private static final boolean supported;
+
+
+    static {
+        Method m1 = null;
+        try {
+            m1 = Process.class.getMethod("waitFor", Duration.class);
+        } catch (NoSuchMethodException e) {
+            // Must be pre-Java 24
+            log.debug(sm.getString("jre22Compat.javaPre24"), e);
+        }
+        supported = (m1 != null);
+    }
+
+    static boolean isSupported() {
+        return supported;
+    }
+
+}
diff --git a/java/org/apache/tomcat/util/compat/JreCompat.java 
b/java/org/apache/tomcat/util/compat/JreCompat.java
index 6fe6254e04..f243178c5b 100644
--- a/java/org/apache/tomcat/util/compat/JreCompat.java
+++ b/java/org/apache/tomcat/util/compat/JreCompat.java
@@ -24,6 +24,7 @@ public class JreCompat {
 
     private static final JreCompat instance;
     private static final boolean graalAvailable;
+    private static final boolean jre24Available;
     private static final boolean jre22Available;
 
     static {
@@ -40,11 +41,17 @@ public class JreCompat {
 
         // This is Tomcat 12.0.x with a minimum Java version of Java 21.
         // Look for the highest supported JVM first
-        if (Jre22Compat.isSupported()) {
+        if (Jre24Compat.isSupported()) {
+            instance = new Jre24Compat();
+            jre24Available = true;
+            jre22Available = true;
+        } else if (Jre22Compat.isSupported()) {
             instance = new Jre22Compat();
+            jre24Available = false;
             jre22Available = true;
         } else {
             instance = new JreCompat();
+            jre24Available = false;
             jre22Available = false;
         }
     }
@@ -63,4 +70,9 @@ public class JreCompat {
     public static boolean isJre22Available() {
         return jre22Available;
     }
+
+
+    public static boolean isJre24Available() {
+        return jre24Available;
+    }
 }
diff --git a/java/org/apache/tomcat/util/compat/LocalStrings.properties 
b/java/org/apache/tomcat/util/compat/LocalStrings.properties
index 0df209897e..51e2b7fc84 100644
--- a/java/org/apache/tomcat/util/compat/LocalStrings.properties
+++ b/java/org/apache/tomcat/util/compat/LocalStrings.properties
@@ -14,3 +14,5 @@
 # limitations under the License.
 
 jre22Compat.javaPre22=Class not found so assuming code is running on a 
pre-Java 22 JVM
+
+jre24Compat.javaPre24=Method not found so assuming code is running on a 
pre-Java 24 JVM


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

Reply via email to