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

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

commit 94b2b6dfc5b79ba3d533841d269ae511864dccf3
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Mon Jan 16 18:02:16 2023 +0000

    Add a Jre16 check - required by unit tests
---
 .../org/apache/tomcat/util/compat/Jre16Compat.java | 47 ++++++++++++++++++++++
 .../org/apache/tomcat/util/compat/Jre19Compat.java |  2 +-
 java/org/apache/tomcat/util/compat/JreCompat.java  | 44 +++++++++++++-------
 3 files changed, 78 insertions(+), 15 deletions(-)

diff --git a/java/org/apache/tomcat/util/compat/Jre16Compat.java 
b/java/org/apache/tomcat/util/compat/Jre16Compat.java
new file mode 100644
index 0000000000..ab436cde17
--- /dev/null
+++ b/java/org/apache/tomcat/util/compat/Jre16Compat.java
@@ -0,0 +1,47 @@
+/*
+ *  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 org.apache.juli.logging.Log;
+import org.apache.juli.logging.LogFactory;
+import org.apache.tomcat.util.res.StringManager;
+
+class Jre16Compat extends Jre9Compat {
+
+    private static final Log log = LogFactory.getLog(Jre16Compat.class);
+    private static final StringManager sm = 
StringManager.getManager(Jre16Compat.class);
+
+    private static final Class<?> unixDomainSocketAddressClazz;
+
+    static {
+        Class<?> c1 = null;
+        try {
+            c1 = Class.forName("java.net.UnixDomainSocketAddress");
+        } catch (ClassNotFoundException e) {
+            // Must be pre-Java 16
+            log.debug(sm.getString("jre16Compat.javaPre16"), e);
+        } catch (IllegalArgumentException e) {
+            // Should never happen
+            log.error(sm.getString("jre16Compat.unexpected"), e);
+        }
+        unixDomainSocketAddressClazz = c1;
+    }
+
+    static boolean isSupported() {
+        return unixDomainSocketAddressClazz != null;
+    }
+}
diff --git a/java/org/apache/tomcat/util/compat/Jre19Compat.java 
b/java/org/apache/tomcat/util/compat/Jre19Compat.java
index 7f120c4d61..fb94810b40 100644
--- a/java/org/apache/tomcat/util/compat/Jre19Compat.java
+++ b/java/org/apache/tomcat/util/compat/Jre19Compat.java
@@ -22,7 +22,7 @@ import org.apache.juli.logging.Log;
 import org.apache.juli.logging.LogFactory;
 import org.apache.tomcat.util.res.StringManager;
 
-public class Jre19Compat extends Jre9Compat {
+public class Jre19Compat extends Jre16Compat {
 
     private static final Log log = LogFactory.getLog(Jre19Compat.class);
     private static final StringManager sm = 
StringManager.getManager(Jre19Compat.class);
diff --git a/java/org/apache/tomcat/util/compat/JreCompat.java 
b/java/org/apache/tomcat/util/compat/JreCompat.java
index 6780664285..87fd07f5e1 100644
--- a/java/org/apache/tomcat/util/compat/JreCompat.java
+++ b/java/org/apache/tomcat/util/compat/JreCompat.java
@@ -45,6 +45,7 @@ public class JreCompat {
 
     private static final JreCompat instance;
     private static final boolean jre19Available;
+    private static final boolean jre16Available;
     private static final boolean jre11Available;
     private static final boolean jre9Available;
     private static final boolean jre8Available;
@@ -57,21 +58,31 @@ public class JreCompat {
         if (Jre19Compat.isSupported()) {
             instance = new Jre19Compat();
             jre19Available = true;
+            jre16Available = true;
+            jre9Available = true;
+            jre8Available = true;
+        } else if (Jre16Compat.isSupported()) {
+            instance = new Jre16Compat();
+            jre19Available = false;
+            jre16Available = true;
             jre9Available = true;
             jre8Available = true;
         } else if (Jre9Compat.isSupported()) {
             instance = new Jre9Compat();
             jre19Available = false;
+            jre16Available = false;
             jre9Available = true;
             jre8Available = true;
         } else if (Jre8Compat.isSupported()) {
             instance = new Jre8Compat();
             jre19Available = false;
+            jre16Available = false;
             jre9Available = false;
             jre8Available = true;
         } else {
             instance = new JreCompat();
             jre19Available = false;
+            jre16Available = false;
             jre9Available = false;
             jre8Available = false;
         }
@@ -84,13 +95,28 @@ public class JreCompat {
     }
 
 
-    // Java 7 implementation of Java 8 methods
+    public static boolean isAlpnSupported() {
+        return isJre9Available() || (isJre8Available() && 
Jre8Compat.isAlpnSupported());
+    }
+
 
     public static boolean isJre8Available() {
         return jre8Available;
     }
 
 
+    public static boolean isJre9Available() {
+        return jre9Available;
+    }
+
+
+    public static boolean isJre16Available() {
+        return jre16Available;
+    }
+
+
+    // Java 7 implementation of Java 8 methods
+
     @SuppressWarnings("unused")
     public void setUseServerCipherSuitesOrder(SSLParameters engine, boolean 
useCipherSuitesOrder) {
         throw new 
UnsupportedOperationException(sm.getString("jreCompat.noServerCipherSuiteOrder"));
@@ -105,16 +131,6 @@ public class JreCompat {
 
     // Java 7 implementation of Java 9 methods
 
-    public static boolean isAlpnSupported() {
-        return isJre9Available() || (isJre8Available() && 
Jre8Compat.isAlpnSupported());
-    }
-
-
-    public static boolean isJre9Available() {
-        return jre9Available;
-    }
-
-
     /**
      * Test if the provided exception is an instance of
      * java.lang.reflect.InaccessibleObjectException.
@@ -133,9 +149,9 @@ public class JreCompat {
     /**
      * Set the application protocols the server will accept for ALPN
      *
-     * @param sslParameters    The SSL parameters for a connection
-     * @param protocols        The application protocols to be allowed for that
-     *                         connection
+     * @param sslParameters The SSL parameters for a connection
+     * @param protocols     The application protocols to be allowed for that
+     *                      connection
      */
     public void setApplicationProtocols(SSLParameters sslParameters, String[] 
protocols) {
         throw new 
UnsupportedOperationException(sm.getString("jreCompat.noApplicationProtocols"));


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

Reply via email to