This is an automated email from the ASF dual-hosted git repository. remm pushed a commit to branch 10.1.x in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/10.1.x by this push: new 0726a5a581 Add JreCompat for Java 22 0726a5a581 is described below commit 0726a5a581ec80e381e23eb36c021a50319fc9df Author: remm <r...@apache.org> AuthorDate: Fri Aug 4 09:20:18 2023 +0200 Add JreCompat for Java 22 --- .../org/apache/tomcat/util/compat/Jre22Compat.java | 54 ++++++++++++++++++++++ java/org/apache/tomcat/util/compat/JreCompat.java | 18 +++++++- .../tomcat/util/compat/LocalStrings.properties | 3 ++ 3 files changed, 74 insertions(+), 1 deletion(-) diff --git a/java/org/apache/tomcat/util/compat/Jre22Compat.java b/java/org/apache/tomcat/util/compat/Jre22Compat.java new file mode 100644 index 0000000000..486cc8a804 --- /dev/null +++ b/java/org/apache/tomcat/util/compat/Jre22Compat.java @@ -0,0 +1,54 @@ +/* + * 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 org.apache.juli.logging.Log; +import org.apache.juli.logging.LogFactory; +import org.apache.tomcat.util.res.StringManager; + +public class Jre22Compat extends Jre21Compat { + + private static final Log log = LogFactory.getLog(Jre22Compat.class); + private static final StringManager sm = StringManager.getManager(Jre22Compat.class); + + private static final boolean hasPanama; + + + static { + Class<?> c1 = null; + Method m1 = null; + + try { + c1 = Class.forName("java.lang.foreign.MemorySegment"); + m1 = c1.getMethod("getString", long.class); + } catch (ClassNotFoundException e) { + // Must be pre-Java 22 + log.debug(sm.getString("jre22Compat.javaPre22"), e); + } catch (ReflectiveOperationException e) { + // Should never happen + log.error(sm.getString("jre22Compat.unexpected"), e); + } + hasPanama = (m1 != null); + } + + static boolean isSupported() { + return hasPanama; + } + +} diff --git a/java/org/apache/tomcat/util/compat/JreCompat.java b/java/org/apache/tomcat/util/compat/JreCompat.java index 79d6a15ed9..86f540bfec 100644 --- a/java/org/apache/tomcat/util/compat/JreCompat.java +++ b/java/org/apache/tomcat/util/compat/JreCompat.java @@ -35,6 +35,7 @@ public class JreCompat { private static final boolean jre16Available; private static final boolean jre19Available; private static final boolean jre21Available; + private static final boolean jre22Available; private static final StringManager sm = StringManager.getManager(JreCompat.class); static { @@ -51,23 +52,33 @@ public class JreCompat { // This is Tomcat 10.1.x with a minimum Java version of Java 11. // Look for the highest supported JVM first - if (Jre21Compat.isSupported()) { + if (Jre22Compat.isSupported()) { + instance = new Jre22Compat(); + jre22Available = true; + jre21Available = true; + jre19Available = true; + jre16Available = true; + } else if (Jre21Compat.isSupported()) { instance = new Jre21Compat(); + jre22Available = false; jre21Available = true; jre19Available = true; jre16Available = true; } else if (Jre19Compat.isSupported()) { instance = new Jre19Compat(); + jre22Available = false; jre21Available = false; jre19Available = true; jre16Available = true; } else if (Jre16Compat.isSupported()) { instance = new Jre16Compat(); + jre22Available = false; jre21Available = false; jre19Available = false; jre16Available = true; } else { instance = new JreCompat(); + jre22Available = false; jre21Available = false; jre19Available = false; jre16Available = false; @@ -100,6 +111,11 @@ public class JreCompat { } + public static boolean isJre22Available() { + return jre22Available; + } + + // Java 11 implementations of Java 16 methods /** diff --git a/java/org/apache/tomcat/util/compat/LocalStrings.properties b/java/org/apache/tomcat/util/compat/LocalStrings.properties index b550e42156..e86cdb55e8 100644 --- a/java/org/apache/tomcat/util/compat/LocalStrings.properties +++ b/java/org/apache/tomcat/util/compat/LocalStrings.properties @@ -21,5 +21,8 @@ jre19Compat.javaPre19=Class not found so assuming code is running on a pre-Java jre21Compat.javaPre21=Class not found so assuming code is running on a pre-Java 21 JVM jre21Compat.unexpected=Failed to create references to Java 21 classes and methods +jre22Compat.javaPre22=Class not found so assuming code is running on a pre-Java 22 JVM +jre22Compat.unexpected=Failed to create references to Java 22 classes and methods + jreCompat.noUnixDomainSocket=Java Runtime does not support Unix domain sockets. You must use Java 16 or later to use this feature. jreCompat.noVirtualThreads=Java Runtime does not support virtual threads. You must use Java 21 or later to use this feature. --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org