From 4386cf394a8e40b1cbbecc85d70b6d4abb529f67 Mon Sep 17 00:00:00 2001 From: Rauneet Singh Date: Sun, 11 Oct 2026 13:28:03 +0530 Subject: [PATCH] Clean up obsolete Java version checks in tests (#27523) --- core/src/test/java/hudson/FunctionsTest.java | 32 +------------------ .../hudson/slaves/ComputerLauncherTest.java | 16 ++++++++++ .../routines/DomainValidatorTest.java | 14 +++----- .../validator/routines/UrlValidatorTest.java | 7 +--- .../jenkins/model/JenkinsLogRecordsTest.java | 31 ++++++++---------- 5 files changed, 36 insertions(+), 64 deletions(-) diff --git a/core/src/test/java/hudson/FunctionsTest.java b/core/src/test/java/hudson/FunctionsTest.java index a91ac84f32..a92712300d 100644 --- a/core/src/test/java/hudson/FunctionsTest.java +++ b/core/src/test/java/hudson/FunctionsTest.java @@ -47,7 +47,6 @@ import hudson.model.ItemGroup; import hudson.model.TopLevelItem; import hudson.model.View; import hudson.model.ViewGroup; -import hudson.util.VersionNumber; import java.io.PrintWriter; import java.io.StringWriter; import java.util.Arrays; @@ -645,11 +644,7 @@ class FunctionsTest { Stack stack2 = new Stack("p.Exc2", "p.C.method2:27"); stack1.cause(stack2); stack2.cause(stack1); - //Format changed in 11.0.9 / 8.0.272 (JDK-8226809 / JDK-8252444 / JDK-8252489) - - if (getVersion().isNewerThanOrEqualTo(new VersionNumber("11.0.9")) || - (getVersion().getDigitAt(0) == 8 && getVersion().isNewerThanOrEqualTo(new VersionNumber("8.0.272")))) { - assertPrintThrowable(stack1, + assertPrintThrowable(stack1, """ p.Exc1 \tat p.C.method1(C.java:17) @@ -664,31 +659,6 @@ class FunctionsTest { Caused: p.Exc1 \tat p.C.method1(C.java:17) """); - } else { - assertPrintThrowable(stack1, - """ - p.Exc1 - \tat p.C.method1(C.java:17) - Caused by: p.Exc2 - \tat p.C.method2(C.java:27) - \t[CIRCULAR REFERENCE:p.Exc1] - """, - """ - - Caused: p.Exc2 - \tat p.C.method2(C.java:27) - Caused: p.Exc1 - \tat p.C.method1(C.java:17) - """); - } - } - - private static VersionNumber getVersion() { - String version = System.getProperty("java.version"); - if (version.startsWith("1.")) { - version = version.substring(2).replace("_", "."); - } - return new VersionNumber(version); } private static void assertPrintThrowable(Throwable t, String traditional, String custom) { diff --git a/core/src/test/java/hudson/slaves/ComputerLauncherTest.java b/core/src/test/java/hudson/slaves/ComputerLauncherTest.java index 6334186cc1..fe0fe0a31c 100644 --- a/core/src/test/java/hudson/slaves/ComputerLauncherTest.java +++ b/core/src/test/java/hudson/slaves/ComputerLauncherTest.java @@ -167,6 +167,22 @@ class ComputerLauncherTest { OpenJDK 64-Bit Server VM Zulu11.35+15-CA (build 11.0.5+10-LTS, mixed mode)""", "11.0.5"); } + @Test + void openJDK21() throws IOException { + assertChecked(""" + openjdk version "21.0.2" 2024-01-16 + OpenJDK Runtime Environment Temurin-21.0.2+13 (build 21.0.2+13) + OpenJDK 64-Bit Server VM Temurin-21.0.2+13 (build 21.0.2+13, mixed mode, sharing)""", "21.0.2"); + } + + @Test + void openJDK25() throws IOException { + assertChecked(""" + openjdk version "25.0.1" 2026-10-20 + OpenJDK Runtime Environment Temurin-25.0.1+8 (build 25.0.1+8) + OpenJDK 64-Bit Server VM Temurin-25.0.1+8 (build 25.0.1+8, mixed mode, sharing)""", "25.0.1"); + } + private static void assertChecked(String text, String spec) throws IOException { ByteArrayOutputStream os = new ByteArrayOutputStream(); ComputerLauncher.checkJavaVersion(new PrintStream(os, false, Charset.defaultCharset()), "bin/java", new BufferedReader(new StringReader(text))); diff --git a/core/src/test/java/jenkins/org/apache/commons/validator/routines/DomainValidatorTest.java b/core/src/test/java/jenkins/org/apache/commons/validator/routines/DomainValidatorTest.java index 6e49d62ba5..bc1879f7f4 100644 --- a/core/src/test/java/jenkins/org/apache/commons/validator/routines/DomainValidatorTest.java +++ b/core/src/test/java/jenkins/org/apache/commons/validator/routines/DomainValidatorTest.java @@ -150,15 +150,11 @@ class DomainValidatorTest { @Test void testIDNJava6OrLater() { - String version = System.getProperty("java.version"); - if (version.compareTo("1.6") < 0) { - System.out.println("Cannot run Unicode IDN tests"); - return; // Cannot run the test - } // xn--d1abbgf6aiiy.xn--p1ai http://президент.рф - assertTrue(validator.isValid("www.b\u00fccher.ch"), "b\u00fccher.ch should validate"); - assertTrue(validator.isValid("xn--d1abbgf6aiiy.xn--p1ai"), "xn--d1abbgf6aiiy.xn--p1ai should validate"); - assertTrue(validator.isValid("президент.рф"), "президент.рф should validate"); - assertFalse(validator.isValid("www.\uFFFD.ch"), "www.\uFFFD.ch FFFD should fail"); + // xn--d1abbgf6aiiy.xn--p1ai http://президент.рф + assertTrue(validator.isValid("www.b\u00fccher.ch"), "b\u00fccher.ch should validate"); + assertTrue(validator.isValid("xn--d1abbgf6aiiy.xn--p1ai"), "xn--d1abbgf6aiiy.xn--p1ai should validate"); + assertTrue(validator.isValid("президент.рф"), "президент.рф should validate"); + assertFalse(validator.isValid("www.\uFFFD.ch"), "www.\uFFFD.ch FFFD should fail"); } // RFC2396: domainlabel = alphanum | alphanum *( alphanum | "-" ) alphanum diff --git a/core/src/test/java/jenkins/org/apache/commons/validator/routines/UrlValidatorTest.java b/core/src/test/java/jenkins/org/apache/commons/validator/routines/UrlValidatorTest.java index 22b78344a9..7807a0ba93 100644 --- a/core/src/test/java/jenkins/org/apache/commons/validator/routines/UrlValidatorTest.java +++ b/core/src/test/java/jenkins/org/apache/commons/validator/routines/UrlValidatorTest.java @@ -155,12 +155,7 @@ class UrlValidatorTest { @Test void testValidator235() { - String version = System.getProperty("java.version"); - if (version.compareTo("1.6") < 0) { - System.out.println("Cannot run Unicode IDN tests"); - return; // Cannot run the test - } - UrlValidator validator = new UrlValidator(); + UrlValidator validator = new UrlValidator(); assertTrue(validator.isValid("http://xn--d1abbgf6aiiy.xn--p1ai"), "xn--d1abbgf6aiiy.xn--p1ai should validate"); assertTrue(validator.isValid("http://президент.рф"), "президент.рф should validate"); assertTrue(validator.isValid("http://www.b\u00fccher.ch"), "www.b\u00fccher.ch should validate"); diff --git a/test/src/test/java/jenkins/model/JenkinsLogRecordsTest.java b/test/src/test/java/jenkins/model/JenkinsLogRecordsTest.java index 3a5cf981e7..5c4b42ecf6 100644 --- a/test/src/test/java/jenkins/model/JenkinsLogRecordsTest.java +++ b/test/src/test/java/jenkins/model/JenkinsLogRecordsTest.java @@ -6,13 +6,11 @@ import static org.hamcrest.Matchers.empty; import static org.hamcrest.Matchers.hasItem; import static org.hamcrest.Matchers.not; -import hudson.util.VersionNumber; import java.lang.ref.WeakReference; import java.util.List; import java.util.logging.LogRecord; import java.util.logging.Logger; import java.util.stream.Collectors; -import jenkins.util.java.JavaUtils; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; import org.jvnet.hudson.test.JenkinsRule; @@ -35,22 +33,19 @@ class JenkinsLogRecordsTest { assertThat("Records are displayed in reverse order", logRecords.stream().map(LogRecord::getMessage).collect(Collectors.toList()), containsInRelativeOrder("Completed initialization", "Started initialization")); - VersionNumber javaVersion = new VersionNumber(JavaUtils.getCurrentRuntimeJavaVersion()); - if (javaVersion.isNewerThanOrEqualTo(new VersionNumber("17"))) { // TODO https://github.com/jenkinsci/jenkins-test-harness/issues/359 - Object x = new Object() { - @Override - public String toString() { - return "collect me"; - } - }; - use(x); - WeakReference ref = new WeakReference<>(x); - x = null; - MemoryAssert.assertGC(ref, true); - assertThat("Record parameters formatted before collection", - logRecords.stream().map(LogRecord::getMessage).collect(Collectors.toList()), - hasItem("formatting collect me")); - } + Object x = new Object() { + @Override + public String toString() { + return "collect me"; + } + }; + use(x); + WeakReference ref = new WeakReference<>(x); + x = null; + MemoryAssert.assertGC(ref, true); + assertThat("Record parameters formatted before collection", + logRecords.stream().map(LogRecord::getMessage).collect(Collectors.toList()), + hasItem("formatting collect me")); } private static void use(Object x) {