This is an automated email from the ASF dual-hosted git repository.
remm 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 43bdf2f71c Add JreCompat for Java 22
43bdf2f71c is described below
commit 43bdf2f71cb904483d39b91f5955ae42344ff0d2
Author: remm <[email protected]>
AuthorDate: Fri Aug 4 09:28:32 2023 +0200
Add JreCompat for Java 22
---
.../org/apache/tomcat/util/compat/Jre22Compat.java | 54 ++++++++++++++++++++++
java/org/apache/tomcat/util/compat/JreCompat.java | 20 +++++++-
.../tomcat/util/compat/LocalStrings.properties | 3 ++
3 files changed, 76 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 c0ac778ba2..0c1840c90b 100644
--- a/java/org/apache/tomcat/util/compat/JreCompat.java
+++ b/java/org/apache/tomcat/util/compat/JreCompat.java
@@ -51,6 +51,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);
protected static final Method setApplicationProtocolsMethod;
@@ -70,32 +71,44 @@ public class JreCompat {
// This is Tomcat 9 with a minimum Java version of Java 8.
// Look for the highest supported JVM first
- if (Jre21Compat.isSupported()) {
+ if (Jre22Compat.isSupported()) {
+ instance = new Jre22Compat();
+ jre22Available = true;
+ jre21Available = true;
+ jre19Available = true;
+ jre16Available = true;
+ jre9Available = true;
+ } else if (Jre21Compat.isSupported()) {
instance = new Jre21Compat();
+ jre22Available = false;
jre21Available = true;
jre19Available = true;
jre16Available = true;
jre9Available = true;
} else if (Jre19Compat.isSupported()) {
instance = new Jre19Compat();
+ jre22Available = false;
jre21Available = false;
jre19Available = true;
jre16Available = true;
jre9Available = true;
} else if (Jre16Compat.isSupported()) {
instance = new Jre16Compat();
+ jre22Available = false;
jre21Available = false;
jre19Available = false;
jre16Available = true;
jre9Available = true;
} else if (Jre9Compat.isSupported()) {
instance = new Jre9Compat();
+ jre22Available = false;
jre21Available = false;
jre19Available = false;
jre16Available = false;
jre9Available = true;
} else {
instance = new JreCompat();
+ jre22Available = false;
jre21Available = false;
jre19Available = false;
jre16Available = false;
@@ -156,6 +169,11 @@ public class JreCompat {
}
+ public static boolean isJre22Available() {
+ return jre22Available;
+ }
+
+
// Java 8 implementation of Java 9 methods
/**
diff --git a/java/org/apache/tomcat/util/compat/LocalStrings.properties
b/java/org/apache/tomcat/util/compat/LocalStrings.properties
index fa26edd7dd..f9bbc23f24 100644
--- a/java/org/apache/tomcat/util/compat/LocalStrings.properties
+++ b/java/org/apache/tomcat/util/compat/LocalStrings.properties
@@ -21,6 +21,9 @@ 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
+
jre9Compat.invalidModuleUri=The module URI provided [{0}] could not be
converted to a URL for the JarScanner to process
jre9Compat.javaPre9=Class not found so assuming code is running on a pre-Java
9 JVM
jre9Compat.unexpected=Failed to create references to Java 9 classes and methods
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]