Introduce getMostSpecificMethod variant on BridgeMethodResolver

This is able to resolve the original method even if no bridge method has been generated at the same class hierarchy level (a known difference between the Eclipse compiler and regular javac).

Closes gh-21843
This commit is contained in:
Juergen Hoeller
2024-01-07 16:33:06 +01:00
parent f0e16bd31b
commit 419e34e571
5 changed files with 77 additions and 39 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -86,6 +86,17 @@ class BridgeMethodResolverTests {
assertThat(bridgedMethod.getParameterTypes()[0]).isEqualTo(Date.class);
}
@Test
void findBridgedMethodFromOriginalMethodInHierarchy() throws Exception {
Method originalMethod = Adder.class.getMethod("add", Object.class);
assertThat(originalMethod.isBridge()).isFalse();
Method bridgedMethod = BridgeMethodResolver.getMostSpecificMethod(originalMethod, DateAdder.class);
assertThat(bridgedMethod.isBridge()).isFalse();
assertThat(bridgedMethod.getName()).isEqualTo("add");
assertThat(bridgedMethod.getParameterCount()).isEqualTo(1);
assertThat(bridgedMethod.getParameterTypes()[0]).isEqualTo(Date.class);
}
@Test
void isBridgeMethodFor() throws Exception {
Method bridged = MyBar.class.getDeclaredMethod("someMethod", String.class, Object.class);