This is an automated email from the ASF dual-hosted git repository. remm 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 7e6af38a62 Add JreCompat for Java 22 7e6af38a62 is described below commit 7e6af38a62b6354869f979ac718a270b70e6ec4d Author: remm <r...@apache.org> AuthorDate: Fri Aug 4 09:13:16 2023 +0200 Add JreCompat for Java 22 Actually the one with the non preview Panama. --- .../org/apache/tomcat/util/compat/Jre22Compat.java | 54 ++++++++++++++++++++++ java/org/apache/tomcat/util/compat/JreCompat.java | 16 ++++++- .../tomcat/util/compat/LocalStrings.properties | 17 +++++++ 3 files changed, 86 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..0b690164b6 --- /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 JreCompat { + + 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 334115acc3..7273b0b233 100644 --- a/java/org/apache/tomcat/util/compat/JreCompat.java +++ b/java/org/apache/tomcat/util/compat/JreCompat.java @@ -25,6 +25,7 @@ public class JreCompat { private static final JreCompat instance; private static final boolean graalAvailable; + private static final boolean jre22Available; static { boolean result = false; @@ -39,7 +40,13 @@ public class JreCompat { graalAvailable = result || System.getProperty("org.graalvm.nativeimage.imagecode") != null; // This is Tomcat 11.0.x with a minimum Java version of Java 21. - instance = new JreCompat(); + if (Jre22Compat.isSupported()) { + instance = new Jre22Compat(); + jre22Available = true; + } else { + instance = new JreCompat(); + jre22Available = false; + } } @@ -51,4 +58,11 @@ public class JreCompat { public static boolean isGraalAvailable() { return graalAvailable; } + + + public static boolean isJre22Available() { + return jre22Available; + } + + } diff --git a/java/org/apache/tomcat/util/compat/LocalStrings.properties b/java/org/apache/tomcat/util/compat/LocalStrings.properties new file mode 100644 index 0000000000..e3bbf2b43b --- /dev/null +++ b/java/org/apache/tomcat/util/compat/LocalStrings.properties @@ -0,0 +1,17 @@ +# 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. + +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 --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org