Skip to content

Commit

Permalink
Add Java 24 detection to JreCompat
Browse files Browse the repository at this point in the history
  • Loading branch information
markt-asf committed Jan 17, 2025
1 parent ad1e7bb commit 13be7d0
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 1 deletion.
49 changes: 49 additions & 0 deletions java/org/apache/tomcat/util/compat/Jre24Compat.java
Original file line number Diff line number Diff line change
@@ -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;
}

}
14 changes: 13 additions & 1 deletion java/org/apache/tomcat/util/compat/JreCompat.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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;
}
}
Expand All @@ -63,4 +70,9 @@ public static boolean isGraalAvailable() {
public static boolean isJre22Available() {
return jre22Available;
}


public static boolean isJre24Available() {
return jre24Available;
}
}
2 changes: 2 additions & 0 deletions java/org/apache/tomcat/util/compat/LocalStrings.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 13be7d0

Please sign in to comment.