Skip to content

Commit 4c75828

Browse files
authored
Add JDK 21 to CI (#109)
1 parent 5c66c89 commit 4c75828

File tree

3 files changed

+56
-22
lines changed

3 files changed

+56
-22
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ jobs:
2323
strategy:
2424
fail-fast: false
2525
matrix:
26-
# 26-Sep-2025, tatu: some test failures on 21 cannot yet enable
27-
java_version: ['8', '11', '17']
26+
java_version: ['8', '17', '21', '25']
2827
env:
2928
JAVA_OPTS: "-XX:+TieredCompilation -XX:TieredStopAtLevel=1"
3029
steps:

src/test/java/com/fasterxml/classmate/AnnotationsTest.java

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,15 @@
77
import java.lang.annotation.RetentionPolicy;
88
import java.lang.reflect.Method;
99

10-
import static junit.framework.Assert.*;
11-
import static org.junit.Assert.assertEquals;
12-
13-
@SuppressWarnings("deprecation")
14-
public class AnnotationsTest {
10+
import static org.junit.Assert.*;
1511

12+
public class AnnotationsTest
13+
{
1614
@Retention(RetentionPolicy.RUNTIME)
1715
private static @interface Marker { }
1816

1917
@Test @Marker
20-
public void addAsDefault() throws NoSuchMethodException {
18+
public void addAsDefault() throws Exception {
2119
Annotations annotations = new Annotations();
2220
Method thisMethod = AnnotationsTest.class.getDeclaredMethod("addAsDefault");
2321

@@ -39,7 +37,7 @@ public void addAsDefault() throws NoSuchMethodException {
3937
}
4038

4139
@Test
42-
public void size() throws NoSuchMethodException {
40+
public void size() throws Exception {
4341
Annotations annotations = new Annotations();
4442
Method thisMethod = AnnotationsTest.class.getDeclaredMethod("addAsDefault");
4543

@@ -57,7 +55,7 @@ public void size() throws NoSuchMethodException {
5755
}
5856

5957
@Test
60-
public void annotationsToSize() throws NoSuchMethodException {
58+
public void annotationsToSize() throws Exception {
6159
Annotations annotations = new Annotations();
6260
Method thisMethod = AnnotationsTest.class.getDeclaredMethod("addAsDefault");
6361

@@ -67,23 +65,42 @@ public void annotationsToSize() throws NoSuchMethodException {
6765
annotations.addAsDefault(testAnnotation);
6866

6967
// order is unspecified as the internal representation is a HashMap; just assert the constituent parts are present
70-
String asString = annotations.toString();
68+
String asString = _normalize(annotations.toString());
7169
assertTrue(asString.contains("{interface org.junit.Test=@org.junit.Test("));
7270
assertTrue(asString.contains("timeout=0"));
7371

7472
// 15-Nov-2016, tatu: Java 9 changes description slightly, need to modify
75-
assertTrue(asString.contains("expected=class org.junit.Test$None") // until Java 8
76-
|| asString.contains("expected=org.junit.Test$None"));
73+
// 05-Dec-2025, tatu: Java 21 adds further variation
74+
if (!(asString.contains("expected=class org.junit.Test.None") // until Java 8
75+
|| asString.contains("expected=org.junit.Test.None"))) {
76+
fail("No 'expected' in: "+asString);
77+
}
7778

7879
Annotation markerAnnotation = thisMethod.getAnnotation(Marker.class);
7980
annotations.addAsDefault(markerAnnotation);
8081

81-
asString = annotations.toString();
82-
assertTrue(asString.contains("interface com.fasterxml.classmate.AnnotationsTest$Marker=@com.fasterxml.classmate.AnnotationsTest$Marker()"));
82+
asString = _normalize(annotations.toString());
83+
84+
String exp = "interface com.fasterxml.classmate.AnnotationsTest.Marker=@com.fasterxml.classmate.AnnotationsTest.Marker()";
85+
if (!asString.contains(exp)) {
86+
fail("Expected: ["+exp+"]\nin ["+asString+"]");
87+
}
8388
assertTrue(asString.contains("interface org.junit.Test=@org.junit.Test"));
8489
assertTrue(asString.contains("timeout=0"));
8590
// 15-Nov-2016, tatu: Java 9 changes description slightly, need to modify
86-
assertTrue(asString.contains("expected=class org.junit.Test$None")
87-
|| asString.contains("expected=org.junit.Test$None"));
91+
// 05-Dec-2025, tatu: Java 21 adds further variation
92+
if (!(asString.contains("expected=class org.junit.Test.None") // until Java 8
93+
|| asString.contains("expected=org.junit.Test.None"))) {
94+
fail("No 'expected' in: "+asString);
95+
}
96+
}
97+
98+
private static String _normalize(String str) {
99+
// 05-Dec-2025, tatu: Java 21 changes from "org.junit.Test$None" to "org.junit.Test.None"
100+
String str2;
101+
while ((str2 = str.replace('$', '.')) != str) {
102+
str = str2;
103+
}
104+
return str;
88105
}
89106
}

src/test/java/com/fasterxml/classmate/TestMemberResolver.java renamed to src/test/java/com/fasterxml/classmate/MemberResolverTest.java

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import com.fasterxml.classmate.types.ResolvedObjectType;
99
import com.fasterxml.classmate.util.ClassKey;
1010

11-
public class TestMemberResolver extends BaseTest
11+
public class MemberResolverTest extends BaseTest
1212
{
1313
/*
1414
/**********************************************************************
@@ -214,7 +214,11 @@ public void testIncludeObject()
214214
mr.setIncludeLangObject(true);
215215

216216
simpleResolvedTypeWithMembers = mr.resolve(simpleResolvedType, null, null);
217-
assertEquals(12, simpleResolvedTypeWithMembers.getMemberMethods().length);
217+
// With JDK < 21, 12 member methods, 21+ 13
218+
int methodCount = simpleResolvedTypeWithMembers.getMemberMethods().length;
219+
if (methodCount < 12 || methodCount > 13) {
220+
fail("Expected [12, 13] methods, got: "+methodCount);
221+
}
218222
assertEquals(1, simpleResolvedTypeWithMembers.getMemberFields().length);
219223
}
220224

@@ -225,7 +229,12 @@ public void testFilters()
225229
mr.setIncludeLangObject(true);
226230

227231
ResolvedTypeWithMembers simpleResolvedTypeWithMembers = mr.resolve(simpleResolvedType, null, null);
228-
assertEquals(12, simpleResolvedTypeWithMembers.getMemberMethods().length);
232+
// With JDK < 21, 12 member methods, 21+ 13
233+
int methodCount = simpleResolvedTypeWithMembers.getMemberMethods().length;
234+
if (methodCount < 12 || methodCount > 13) {
235+
fail("Expected [12, 13] methods, got: "+methodCount);
236+
}
237+
229238
assertEquals(1, simpleResolvedTypeWithMembers.getMemberFields().length);
230239
assertEquals(2, simpleResolvedTypeWithMembers.getConstructors().length);
231240

@@ -253,7 +262,12 @@ public void testFilters()
253262
});
254263

255264
simpleResolvedTypeWithMembers = mr.resolve(simpleResolvedType, null, null);
256-
assertEquals(12, simpleResolvedTypeWithMembers.getMemberMethods().length);
265+
266+
// With JDK < 21, 12 member methods, 21+ 13
267+
methodCount = simpleResolvedTypeWithMembers.getMemberMethods().length;
268+
if (methodCount < 12 || methodCount > 13) {
269+
fail("Expected [12, 13] methods, got: "+methodCount);
270+
}
257271
assertEquals(0, simpleResolvedTypeWithMembers.getMemberFields().length);
258272
assertEquals(2, simpleResolvedTypeWithMembers.getConstructors().length);
259273

@@ -267,7 +281,11 @@ public void testFilters()
267281
});
268282

269283
simpleResolvedTypeWithMembers = mr.resolve(simpleResolvedType, null, null);
270-
assertEquals(12, simpleResolvedTypeWithMembers.getMemberMethods().length);
284+
// With JDK < 21, 12 member methods, 21+ 13
285+
methodCount = simpleResolvedTypeWithMembers.getMemberMethods().length;
286+
if (methodCount < 12 || methodCount > 13) {
287+
fail("Expected [12, 13] methods, got: "+methodCount);
288+
}
271289
assertEquals(1, simpleResolvedTypeWithMembers.getMemberFields().length);
272290
assertEquals(1, simpleResolvedTypeWithMembers.getConstructors().length);
273291
}

0 commit comments

Comments
 (0)