From 9e754eb50273cb86df7d9d81ae03691fe0dcc520 Mon Sep 17 00:00:00 2001 From: Tatu Saloranta Date: Fri, 5 Dec 2025 14:27:24 -0800 Subject: [PATCH 1/6] Add JDK 21 to CI --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 4f2fcc7..c214265 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -24,7 +24,7 @@ jobs: fail-fast: false matrix: # 26-Sep-2025, tatu: some test failures on 21 cannot yet enable - java_version: ['8', '11', '17'] + java_version: ['8', '11', '17', '21'] env: JAVA_OPTS: "-XX:+TieredCompilation -XX:TieredStopAtLevel=1" steps: From 3afc885b94ccf048e9deb8225c7d92cb9f3a15cf Mon Sep 17 00:00:00 2001 From: Tatu Saloranta Date: Fri, 5 Dec 2025 14:55:18 -0800 Subject: [PATCH 2/6] Fix one JDK 21 test failure --- .../fasterxml/classmate/AnnotationsTest.java | 48 +++++++++++++------ 1 file changed, 33 insertions(+), 15 deletions(-) diff --git a/src/test/java/com/fasterxml/classmate/AnnotationsTest.java b/src/test/java/com/fasterxml/classmate/AnnotationsTest.java index 096bed3..d03b5fc 100644 --- a/src/test/java/com/fasterxml/classmate/AnnotationsTest.java +++ b/src/test/java/com/fasterxml/classmate/AnnotationsTest.java @@ -7,17 +7,15 @@ import java.lang.annotation.RetentionPolicy; import java.lang.reflect.Method; -import static junit.framework.Assert.*; -import static org.junit.Assert.assertEquals; - -@SuppressWarnings("deprecation") -public class AnnotationsTest { +import static org.junit.Assert.*; +public class AnnotationsTest +{ @Retention(RetentionPolicy.RUNTIME) private static @interface Marker { } @Test @Marker - public void addAsDefault() throws NoSuchMethodException { + public void addAsDefault() throws Exception { Annotations annotations = new Annotations(); Method thisMethod = AnnotationsTest.class.getDeclaredMethod("addAsDefault"); @@ -39,7 +37,7 @@ public void addAsDefault() throws NoSuchMethodException { } @Test - public void size() throws NoSuchMethodException { + public void size() throws Exception { Annotations annotations = new Annotations(); Method thisMethod = AnnotationsTest.class.getDeclaredMethod("addAsDefault"); @@ -57,7 +55,7 @@ public void size() throws NoSuchMethodException { } @Test - public void annotationsToSize() throws NoSuchMethodException { + public void annotationsToSize() throws Exception { Annotations annotations = new Annotations(); Method thisMethod = AnnotationsTest.class.getDeclaredMethod("addAsDefault"); @@ -67,23 +65,43 @@ public void annotationsToSize() throws NoSuchMethodException { annotations.addAsDefault(testAnnotation); // order is unspecified as the internal representation is a HashMap; just assert the constituent parts are present - String asString = annotations.toString(); + String asString = _normalize(annotations.toString()); assertTrue(asString.contains("{interface org.junit.Test=@org.junit.Test(")); assertTrue(asString.contains("timeout=0")); // 15-Nov-2016, tatu: Java 9 changes description slightly, need to modify - assertTrue(asString.contains("expected=class org.junit.Test$None") // until Java 8 - || asString.contains("expected=org.junit.Test$None")); + // 05-Dec-2025, tatu: Java 21 adds further variation + if (!(asString.contains("expected=class org.junit.Test.None") // until Java 8 + || asString.contains("expected=org.junit.Test.None"))) { + fail("No 'expected' in: "+asString); + } Annotation markerAnnotation = thisMethod.getAnnotation(Marker.class); annotations.addAsDefault(markerAnnotation); - asString = annotations.toString(); - assertTrue(asString.contains("interface com.fasterxml.classmate.AnnotationsTest$Marker=@com.fasterxml.classmate.AnnotationsTest$Marker()")); + asString = _normalize(annotations.toString()); + + String exp = "interface com.fasterxml.classmate.AnnotationsTest.Marker=@com.fasterxml.classmate.AnnotationsTest.Marker()"; + if (!asString.contains(exp)) { + fail("Expected: ["+exp+"]\nin ["+asString+"]"); + } assertTrue(asString.contains("interface org.junit.Test=@org.junit.Test")); assertTrue(asString.contains("timeout=0")); // 15-Nov-2016, tatu: Java 9 changes description slightly, need to modify - assertTrue(asString.contains("expected=class org.junit.Test$None") - || asString.contains("expected=org.junit.Test$None")); + // 05-Dec-2025, tatu: Java 21 adds further variation + if (!(asString.contains("expected=class org.junit.Test$None") // until Java 8 + || asString.contains("expected=org.junit.Test$None") // Java 9 - 17 + || asString.contains("expected=org.junit.Test.None"))) { + fail("No 'expected' in: "+asString); + } + } + + private static String _normalize(String str) { + // 05-Dec-2025, tatu: Java 21 changes from "org.junit.Test$None" to "org.junit.Test.None" + String str2; + while ((str2 = str.replace('$', '.')) != str) { + str = str2; + } + return str; } } From 706eeff4379823faee51166de2b5afd93e1c192f Mon Sep 17 00:00:00 2001 From: Tatu Saloranta Date: Fri, 5 Dec 2025 15:02:20 -0800 Subject: [PATCH 3/6] Fix other failing tests --- ...rResolver.java => MemberResolverTest.java} | 28 +++++++++++++++---- 1 file changed, 23 insertions(+), 5 deletions(-) rename src/test/java/com/fasterxml/classmate/{TestMemberResolver.java => MemberResolverTest.java} (93%) diff --git a/src/test/java/com/fasterxml/classmate/TestMemberResolver.java b/src/test/java/com/fasterxml/classmate/MemberResolverTest.java similarity index 93% rename from src/test/java/com/fasterxml/classmate/TestMemberResolver.java rename to src/test/java/com/fasterxml/classmate/MemberResolverTest.java index 50c6442..bd05ae6 100644 --- a/src/test/java/com/fasterxml/classmate/TestMemberResolver.java +++ b/src/test/java/com/fasterxml/classmate/MemberResolverTest.java @@ -8,7 +8,7 @@ import com.fasterxml.classmate.types.ResolvedObjectType; import com.fasterxml.classmate.util.ClassKey; -public class TestMemberResolver extends BaseTest +public class MemberResolverTest extends BaseTest { /* /********************************************************************** @@ -214,7 +214,11 @@ public void testIncludeObject() mr.setIncludeLangObject(true); simpleResolvedTypeWithMembers = mr.resolve(simpleResolvedType, null, null); - assertEquals(12, simpleResolvedTypeWithMembers.getMemberMethods().length); + // With JDK < 21, 12 member methods, 21+ 13 + int methodCount = simpleResolvedTypeWithMembers.getMemberMethods().length; + if (methodCount < 12 || methodCount > 13) { + fail("Expected [12, 13] methods, got: "+methodCount); + } assertEquals(1, simpleResolvedTypeWithMembers.getMemberFields().length); } @@ -225,7 +229,12 @@ public void testFilters() mr.setIncludeLangObject(true); ResolvedTypeWithMembers simpleResolvedTypeWithMembers = mr.resolve(simpleResolvedType, null, null); - assertEquals(12, simpleResolvedTypeWithMembers.getMemberMethods().length); + // With JDK < 21, 12 member methods, 21+ 13 + int methodCount = simpleResolvedTypeWithMembers.getMemberMethods().length; + if (methodCount < 12 || methodCount > 13) { + fail("Expected [12, 13] methods, got: "+methodCount); + } + assertEquals(1, simpleResolvedTypeWithMembers.getMemberFields().length); assertEquals(2, simpleResolvedTypeWithMembers.getConstructors().length); @@ -253,7 +262,12 @@ public void testFilters() }); simpleResolvedTypeWithMembers = mr.resolve(simpleResolvedType, null, null); - assertEquals(12, simpleResolvedTypeWithMembers.getMemberMethods().length); + + // With JDK < 21, 12 member methods, 21+ 13 + methodCount = simpleResolvedTypeWithMembers.getMemberMethods().length; + if (methodCount < 12 || methodCount > 13) { + fail("Expected [12, 13] methods, got: "+methodCount); + } assertEquals(0, simpleResolvedTypeWithMembers.getMemberFields().length); assertEquals(2, simpleResolvedTypeWithMembers.getConstructors().length); @@ -267,7 +281,11 @@ public void testFilters() }); simpleResolvedTypeWithMembers = mr.resolve(simpleResolvedType, null, null); - assertEquals(12, simpleResolvedTypeWithMembers.getMemberMethods().length); + // With JDK < 21, 12 member methods, 21+ 13 + methodCount = simpleResolvedTypeWithMembers.getMemberMethods().length; + if (methodCount < 12 || methodCount > 13) { + fail("Expected [12, 13] methods, got: "+methodCount); + } assertEquals(1, simpleResolvedTypeWithMembers.getMemberFields().length); assertEquals(1, simpleResolvedTypeWithMembers.getConstructors().length); } From d829901c9d5a7742bd00c4b2ecbad0dfd3294e44 Mon Sep 17 00:00:00 2001 From: Tatu Saloranta Date: Fri, 5 Dec 2025 15:03:24 -0800 Subject: [PATCH 4/6] ... --- .github/workflows/main.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index c214265..7624da1 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -23,8 +23,7 @@ jobs: strategy: fail-fast: false matrix: - # 26-Sep-2025, tatu: some test failures on 21 cannot yet enable - java_version: ['8', '11', '17', '21'] + java_version: ['8', '11', '17', '21', '25'] env: JAVA_OPTS: "-XX:+TieredCompilation -XX:TieredStopAtLevel=1" steps: From cd459c1b8c1bc6fcfb81c91a7ca0b87a91a3d8ad Mon Sep 17 00:00:00 2001 From: Tatu Saloranta Date: Fri, 5 Dec 2025 15:04:16 -0800 Subject: [PATCH 5/6] fix the fix --- src/test/java/com/fasterxml/classmate/AnnotationsTest.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/test/java/com/fasterxml/classmate/AnnotationsTest.java b/src/test/java/com/fasterxml/classmate/AnnotationsTest.java index d03b5fc..6b0a49e 100644 --- a/src/test/java/com/fasterxml/classmate/AnnotationsTest.java +++ b/src/test/java/com/fasterxml/classmate/AnnotationsTest.java @@ -89,8 +89,7 @@ public void annotationsToSize() throws Exception { assertTrue(asString.contains("timeout=0")); // 15-Nov-2016, tatu: Java 9 changes description slightly, need to modify // 05-Dec-2025, tatu: Java 21 adds further variation - if (!(asString.contains("expected=class org.junit.Test$None") // until Java 8 - || asString.contains("expected=org.junit.Test$None") // Java 9 - 17 + if (!(asString.contains("expected=class org.junit.Test.None") // until Java 8 || asString.contains("expected=org.junit.Test.None"))) { fail("No 'expected' in: "+asString); } From 37275d986de36a36a87f6e8f947dd14838609704 Mon Sep 17 00:00:00 2001 From: Tatu Saloranta Date: Fri, 5 Dec 2025 15:05:22 -0800 Subject: [PATCH 6/6] ... --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 7624da1..0c36f2a 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -23,7 +23,7 @@ jobs: strategy: fail-fast: false matrix: - java_version: ['8', '11', '17', '21', '25'] + java_version: ['8', '17', '21', '25'] env: JAVA_OPTS: "-XX:+TieredCompilation -XX:TieredStopAtLevel=1" steps: