Skip to content

Commit 052407b

Browse files
aoeuicopybara-github
authored andcommitted
Serialization Test fixes for JDK 21.
ImmutableMapCodecTest - was using getCanonicalName to retrieve the name of an anonymous inner class and was getting null, as is the defined behavior for anonymous inner classes. Switching to getName fixes the test, which makes it consistent with production code anyway. MethodCodecTest - this seems like weird JDK21 behavior. Looking up methods returned by Class.getMethods against the declaring classes does not return the same method. In this case, in particular, String.class.getMethods includes java.lang.String.resolveConstantDesc(java.lang.invoke.MethodHandles$Lookup) throws java.lang.ReflectiveOperationException which is the method signature according to the ConstantDesc interface. Adding to the strangeness, calling getDeclaringClass returns String instead of ConstantDesc. However, looking up the method with String.class.getDeclaredMethod by name and parameters, results in java.lang.String.resolveConstantDesc(java.lang.invoke.MethodHandles$Lookup) which drops the ReflectiveOperationException. This is actually the proper signature for strings. This difference shouldn't really matter for serialization correctness as long as both Method objects are invokable. Changing the test to serialize the result of looking up via getDeclaredMethod instead of getMethods fixes it. PiperOrigin-RevId: 514686339 Change-Id: I1eecae589858fc9296fedee49f810d56720d6ab2
1 parent b6fc2d9 commit 052407b

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

src/test/java/com/google/devtools/build/lib/skyframe/serialization/ImmutableMapCodecTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public void immutableSortedMapUnserializableComparatorFails() {
9696
.buildOrThrow()));
9797
assertThat(thrown)
9898
.hasMessageThat()
99-
.startsWith("No default codec available for " + comparator.getClass().getCanonicalName());
99+
.startsWith("No default codec available for " + comparator.getClass().getName());
100100
}
101101

102102
@Test

src/test/java/com/google/devtools/build/lib/skyframe/serialization/MethodCodecTest.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,17 @@
2727
public class MethodCodecTest {
2828
@Test
2929
public void smoke() throws Exception {
30-
new SerializationTester(
31-
ImmutableList.<Method>builder()
32-
.add(String.class.getMethods())
33-
.add(List.class.getMethods())
34-
.build())
35-
.runTests();
30+
var methods = new ImmutableList.Builder<Method>();
31+
getMethods(String.class, methods);
32+
getMethods(List.class, methods);
33+
new SerializationTester(methods.build()).runTests();
34+
}
35+
36+
private static void getMethods(Class<?> clazz, ImmutableList.Builder<Method> out)
37+
throws NoSuchMethodException {
38+
for (var method : clazz.getMethods()) {
39+
Class<?> declaringClass = method.getDeclaringClass();
40+
out.add(declaringClass.getDeclaredMethod(method.getName(), method.getParameterTypes()));
41+
}
3642
}
3743
}

0 commit comments

Comments
 (0)