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

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

commit 41976081e05cfbf21bca6c3e7913678ae593edfe
Author: Mark Thomas <[email protected]>
AuthorDate: Tue Nov 10 12:02:39 2026 +0000

    Add version checks for tests that require Java > 8
---
 .../apache/catalina/realm/TestDataSourceRealm.java  |  4 +++-
 .../catalina/webresources/TestJarContents.java      |  6 ++++--
 .../webresources/TestJarWarResourceSet.java         | 11 +++++++++++
 .../apache/jasper/compiler/TestJavaCompiler.java    |  4 ++--
 .../util/scan/TestAbstractInputStreamJar.java       | 14 ++++++++++++++
 .../apache/tomcat/util/scan/TestJarFileUrlJar.java  | 21 ++++++++++++++++++++-
 test/webapp/jstl/foreach-begin-after-end.jsp        |  2 +-
 7 files changed, 55 insertions(+), 7 deletions(-)

diff --git a/test/org/apache/catalina/realm/TestDataSourceRealm.java 
b/test/org/apache/catalina/realm/TestDataSourceRealm.java
index d0677fdd70..e6627d3b7a 100644
--- a/test/org/apache/catalina/realm/TestDataSourceRealm.java
+++ b/test/org/apache/catalina/realm/TestDataSourceRealm.java
@@ -90,7 +90,7 @@ public class TestDataSourceRealm extends LoggingBaseTest {
     @Test
     public void testRealm() throws Exception {
 
-        Assume.assumeTrue(JreCompat.isJre16Available());
+        Assume.assumeTrue("Database tests require Derby which requires Java 
17+", JreCompat.isJre17Available());
 
         db = new DerbyDataSourceRealm("dsRealm");
         db.setUserTable("users");
@@ -166,6 +166,8 @@ public class TestDataSourceRealm extends LoggingBaseTest {
     @Test
     public void testRealmWithoutRoleStore() throws Exception {
 
+        Assume.assumeTrue("Database tests require Derby which requires Java 
17+", JreCompat.isJre17Available());
+
         db = new DerbyDataSourceRealm("dsRealmNoRoles");
         db.setUserTable("users");
         db.setUserNameCol("user_name");
diff --git a/test/org/apache/catalina/webresources/TestJarContents.java 
b/test/org/apache/catalina/webresources/TestJarContents.java
index 542fed36ce..1419ae3ee2 100644
--- a/test/org/apache/catalina/webresources/TestJarContents.java
+++ b/test/org/apache/catalina/webresources/TestJarContents.java
@@ -156,8 +156,10 @@ public class TestJarContents {
             // Signed version segments are invalid
             
Assert.assertTrue(jarContents.mightContainResource("META-INF/versions/+9/plus.txt"));
             
Assert.assertTrue(jarContents.mightContainResource("META-INF/versions/-9/minus.txt"));
-            // Valid version segments record the base name
-            Assert.assertTrue(jarContents.mightContainResource("ok.txt"));
+            if (JreCompat.isJre9Available()) {
+                // Valid version segments record the base name
+                Assert.assertTrue(jarContents.mightContainResource("ok.txt"));
+            }
         }
     }
 
diff --git a/test/org/apache/catalina/webresources/TestJarWarResourceSet.java 
b/test/org/apache/catalina/webresources/TestJarWarResourceSet.java
index b3a8631d3c..2136d64567 100644
--- a/test/org/apache/catalina/webresources/TestJarWarResourceSet.java
+++ b/test/org/apache/catalina/webresources/TestJarWarResourceSet.java
@@ -30,6 +30,7 @@ import java.util.zip.ZipEntry;
 import java.util.zip.ZipOutputStream;
 
 import org.junit.Assert;
+import org.junit.Assume;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -38,6 +39,7 @@ import org.apache.catalina.LifecycleException;
 import org.apache.catalina.WebResource;
 import org.apache.catalina.startup.Tomcat;
 import org.apache.catalina.startup.TomcatBaseTest;
+import org.apache.tomcat.util.compat.JreCompat;
 
 public class TestJarWarResourceSet extends TomcatBaseTest {
 
@@ -91,6 +93,9 @@ public class TestJarWarResourceSet extends TomcatBaseTest {
 
     @Test
     public void testMultiReleaseWithInvalidVersionDirectories() throws 
Exception {
+
+        Assume.assumeTrue("Multi-release JAR support requires Java 9+", 
JreCompat.isJre9Available());
+
         // An entry below a directory whose name is not a valid version number
         // must not stop the archive index being built. Such an entry is not a
         // versioned entry, so it stays in the index under its full name. An
@@ -142,6 +147,9 @@ public class TestJarWarResourceSet extends TomcatBaseTest {
 
     @Test
     public void testMultiReleaseVersionDirectoryRules() throws Exception {
+
+        Assume.assumeTrue("Multi-release JAR support requires Java 9+", 
JreCompat.isJre9Available());
+
         // Version directories with a sign or a leading zero are not version
         // directories as far as the JDK is concerned. An entry directly below
         // META-INF/versions/ has no version directory at all. All of these
@@ -195,6 +203,9 @@ public class TestJarWarResourceSet extends TomcatBaseTest {
 
     @Test
     public void testMultiReleaseVersionDirectoryEntry() throws Exception {
+
+        Assume.assumeTrue("Multi-release JAR support requires Java 9+", 
JreCompat.isJre9Available());
+
         // The entry for the version directory itself has no resource name so
         // it must not be added to the index as an entry with an empty name.
         File warFile = File.createTempFile("test-jar-war-resource-set", 
".war");
diff --git a/test/org/apache/jasper/compiler/TestJavaCompiler.java 
b/test/org/apache/jasper/compiler/TestJavaCompiler.java
index f4f3c090b9..2565f021b5 100644
--- a/test/org/apache/jasper/compiler/TestJavaCompiler.java
+++ b/test/org/apache/jasper/compiler/TestJavaCompiler.java
@@ -76,9 +76,9 @@ public class TestJavaCompiler {
         Options options = EasyMock.createMock(Options.class);
         EasyMock.expect(options.getJavaEncoding()).andReturn("UTF-8")
                 .anyTimes();
-        EasyMock.expect(options.getCompilerSourceVM()).andReturn("17")
+        EasyMock.expect(options.getCompilerSourceVM()).andReturn("8")
                 .anyTimes();
-        EasyMock.expect(options.getCompilerTargetVM()).andReturn("17")
+        EasyMock.expect(options.getCompilerTargetVM()).andReturn("8")
                 .anyTimes();
         EasyMock.replay(options);
 
diff --git a/test/org/apache/tomcat/util/scan/TestAbstractInputStreamJar.java 
b/test/org/apache/tomcat/util/scan/TestAbstractInputStreamJar.java
index b1f110a86e..9f18aa6ec5 100644
--- a/test/org/apache/tomcat/util/scan/TestAbstractInputStreamJar.java
+++ b/test/org/apache/tomcat/util/scan/TestAbstractInputStreamJar.java
@@ -32,6 +32,7 @@ import java.util.jar.JarOutputStream;
 import java.util.jar.Manifest;
 
 import org.junit.Assert;
+import org.junit.Assume;
 import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
@@ -40,6 +41,7 @@ import org.junit.rules.TemporaryFolder;
 import org.apache.catalina.util.IOTools;
 import org.apache.catalina.webresources.TomcatURLStreamHandlerFactory;
 import org.apache.tomcat.Jar;
+import org.apache.tomcat.util.compat.JreCompat;
 
 public class TestAbstractInputStreamJar {
 
@@ -126,6 +128,8 @@ public class TestAbstractInputStreamJar {
 
     @Test
     public void testMultiReleaseVersionSelected() throws Exception {
+        Assume.assumeTrue("Multi-release JAR support requires Java 9+", 
JreCompat.isJre9Available());
+
         String v9 = VERSIONS + "9/" + BASE_CLASS;
         String v11 = VERSIONS + "11/" + BASE_CLASS;
         try (Jar jar = createJar(v9, v11, BASE_CLASS)) {
@@ -147,6 +151,8 @@ public class TestAbstractInputStreamJar {
      */
     @Test
     public void testMultiReleaseLeadingSlash() throws Exception {
+        Assume.assumeTrue("Multi-release JAR support requires Java 9+", 
JreCompat.isJre9Available());
+
         String versioned = "/" + VERSIONS + "9/" + BASE_CLASS;
         try (Jar jar = createJar(versioned, BASE_CLASS)) {
             Assert.assertEquals(versioned, read(jar, BASE_CLASS));
@@ -174,6 +180,8 @@ public class TestAbstractInputStreamJar {
 
     @Test
     public void testMultiReleaseEntryDirectlyBelowVersionsDirectory() throws 
Exception {
+        Assume.assumeTrue("Multi-release JAR support requires Java 9+", 
JreCompat.isJre9Available());
+
         try (Jar jar = createJar(VERSIONS + "Foo.class", VERSIONS + "9/" + 
BASE_CLASS, BASE_CLASS)) {
             Assert.assertEquals(VERSIONS + "9/" + BASE_CLASS, read(jar, 
BASE_CLASS));
 
@@ -237,6 +245,8 @@ public class TestAbstractInputStreamJar {
      */
     @Test
     public void testMultiReleaseUnselectedLeadingSlashEntryIsHidden() throws 
Exception {
+        Assume.assumeTrue("Multi-release JAR support requires Java 9+", 
JreCompat.isJre9Available());
+
         String lower = "/" + VERSIONS + "9/" + BASE_CLASS;
         String higher = VERSIONS + "11/" + BASE_CLASS;
         try (Jar jar = createJar(lower, higher, BASE_CLASS)) {
@@ -254,6 +264,8 @@ public class TestAbstractInputStreamJar {
      */
     @Test
     public void testMultiReleaseVersionedResourceIsUsed() throws Exception {
+        Assume.assumeTrue("Multi-release JAR support requires Java 9+", 
JreCompat.isJre9Available());
+
         String base = "test/resource.txt";
         String v9 = VERSIONS + "9/" + base;
         String v11 = VERSIONS + "11/" + base;
@@ -271,6 +283,8 @@ public class TestAbstractInputStreamJar {
      */
     @Test
     public void testMultiReleaseVersionedResourceWithoutBaseEntry() throws 
Exception {
+        Assume.assumeTrue("Multi-release JAR support requires Java 9+", 
JreCompat.isJre9Available());
+
         String base = "test/resource.txt";
         String v9 = VERSIONS + "9/" + base;
         try (Jar jar = createJar(v9)) {
diff --git a/test/org/apache/tomcat/util/scan/TestJarFileUrlJar.java 
b/test/org/apache/tomcat/util/scan/TestJarFileUrlJar.java
index c0832ae9a3..1421488c2b 100644
--- a/test/org/apache/tomcat/util/scan/TestJarFileUrlJar.java
+++ b/test/org/apache/tomcat/util/scan/TestJarFileUrlJar.java
@@ -31,11 +31,12 @@ import java.util.jar.JarOutputStream;
 import java.util.jar.Manifest;
 
 import org.junit.Assert;
+import org.junit.Assume;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.TemporaryFolder;
-
 import org.apache.tomcat.Jar;
+import org.apache.tomcat.util.compat.JreCompat;
 
 public class TestJarFileUrlJar {
 
@@ -122,6 +123,8 @@ public class TestJarFileUrlJar {
      */
     @Test
     public void testMultiReleaseFutureVersion() throws Exception {
+        Assume.assumeTrue("Multi-release JAR support requires Java 9+", 
JreCompat.isJre9Available());
+
         // The name is unlikely to ever be a valid class but it is certain to 
be later than the current runtime
         String futureClass = VERSIONS + "999999/" + BASE_CLASS;
 
@@ -149,6 +152,8 @@ public class TestJarFileUrlJar {
      */
     @Test
     public void testMultiReleaseSelectedEntryContent() throws Exception {
+        Assume.assumeTrue("Multi-release JAR support requires Java 9+", 
JreCompat.isJre9Available());
+
         Manifest manifest = new Manifest();
         manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, 
"1.0");
         manifest.getMainAttributes().putValue("Multi-Release", "true");
@@ -187,6 +192,8 @@ public class TestJarFileUrlJar {
      */
     @Test
     public void testMultiReleaseResetAndUnusableEntries() throws Exception {
+        Assume.assumeTrue("Multi-release JAR support requires Java 9+", 
JreCompat.isJre9Available());
+
         String unparseable = VERSIONS + "abc/" + BASE_CLASS;
         String versionedResource = VERSIONS + "9/test/resource.txt";
         String resource = "test/resource.txt";
@@ -213,6 +220,8 @@ public class TestJarFileUrlJar {
      */
     @Test
     public void testMultiReleaseVersionSelectionViaJarUrl() throws Exception {
+        Assume.assumeTrue("Multi-release JAR support requires Java 9+", 
JreCompat.isJre9Available());
+
         File file = createMultiReleaseJar(VERSIONS + "9/" + BASE_CLASS, 
VERSIONS + "11/" + BASE_CLASS, BASE_CLASS);
         URL url = URI.create("jar:" + file.toURI().toURL().toExternalForm() + 
"!/").toURL();
         try (Jar jar = new JarFileUrlJar(url, true)) {
@@ -230,6 +239,8 @@ public class TestJarFileUrlJar {
      */
     @Test
     public void testMultiReleaseEntryDirectlyBelowVersionsDirectory() throws 
Exception {
+        Assume.assumeTrue("Multi-release JAR support requires Java 9+", 
JreCompat.isJre9Available());
+
         File file = createMultiReleaseJar(VERSIONS + "Foo.class", VERSIONS + 
"9/" + BASE_CLASS, BASE_CLASS);
         try (Jar jar = new JarFileUrlJar(file.toURI().toURL(), false)) {
             List<String> names = entryNames(jar);
@@ -264,6 +275,8 @@ public class TestJarFileUrlJar {
      */
     @Test
     public void testMultiReleaseLeadingSlash() throws Exception {
+        Assume.assumeTrue("Multi-release JAR support requires Java 9+", 
JreCompat.isJre9Available());
+
         String versioned = "/" + VERSIONS + "9/" + BASE_CLASS;
         File file = createMultiReleaseJar(versioned, BASE_CLASS);
         try (Jar jar = new JarFileUrlJar(file.toURI().toURL(), false)) {
@@ -280,6 +293,8 @@ public class TestJarFileUrlJar {
      */
     @Test
     public void testMultiReleaseVersionSelectionForResources() throws 
Exception {
+        Assume.assumeTrue("Multi-release JAR support requires Java 9+", 
JreCompat.isJre9Available());
+
         String base = "test/resource.txt";
         String v9 = VERSIONS + "9/" + base;
         String v11 = VERSIONS + "11/" + base;
@@ -403,6 +418,8 @@ public class TestJarFileUrlJar {
 
     @Test
     public void testMultiReleaseLookupByName() throws Exception {
+        Assume.assumeTrue("Multi-release JAR support requires Java 9+", 
JreCompat.isJre9Available());
+
         File file = createLookupJar();
         try (Jar jar = new JarFileUrlJar(file.toURI().toURL(), false)) {
             doTestMultiReleaseLookupByName(jar);
@@ -412,6 +429,8 @@ public class TestJarFileUrlJar {
 
     @Test
     public void testMultiReleaseLookupByNameViaJarUrl() throws Exception {
+        Assume.assumeTrue("Multi-release JAR support requires Java 9+", 
JreCompat.isJre9Available());
+
         File file = createLookupJar();
         URL url = URI.create("jar:" + file.toURI().toURL().toExternalForm() + 
"!/").toURL();
         try (Jar jar = new JarFileUrlJar(url, true)) {
diff --git a/test/webapp/jstl/foreach-begin-after-end.jsp 
b/test/webapp/jstl/foreach-begin-after-end.jsp
index bd3f7c29bb..adbdad06f6 100644
--- a/test/webapp/jstl/foreach-begin-after-end.jsp
+++ b/test/webapp/jstl/foreach-begin-after-end.jsp
@@ -18,7 +18,7 @@
          pageEncoding="UTF-8" import="java.util.Iterator,java.util.List" %>
 <%@ taglib uri="http://java.sun.com/jsp/jstl/core"; prefix="c" %>
 <%
-    Iterator<String> iterator = List.of("a", "b", "c", "d").iterator();
+    Iterator<String> iterator = Arrays.asList("a", "b", "c", "d").iterator();
     pageContext.setAttribute("values", iterator);
     pageContext.setAttribute("array", new String[] { "a", "b", "c", "d" });
 %>


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to