Skip to content
This repository was archived by the owner on Feb 23, 2023. It is now read-only.

Commit 0de6eab

Browse files
committed
Add unit test and filter out synthetic methods
Closes gh-769
1 parent a1611cf commit 0de6eab

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed

spring-aot/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,11 @@
191191
<artifactId>spring-boot-starter-security</artifactId>
192192
<scope>test</scope>
193193
</dependency>
194+
<dependency>
195+
<groupId>org.jetbrains.kotlin</groupId>
196+
<artifactId>kotlin-stdlib-jdk8</artifactId>
197+
<scope>test</scope>
198+
</dependency>
194199
</dependencies>
195200

196201
<build>

spring-aot/src/main/java/org/springframework/aot/context/bootstrap/generator/infrastructure/nativex/NativeConfigurationUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public static Set<Class<?>> collectTypesInSignature(Method controllerMethod) {
6161
Set<Class<?>> collector = new TreeSet<>(Comparator.comparing(Class::getName));
6262
Type genericReturnType;
6363
Type[] genericParameterTypes;
64-
if (KotlinDetector.isSuspendingFunction(controllerMethod)) {
64+
if (KotlinDetector.isSuspendingFunction(controllerMethod) && !controllerMethod.isSynthetic()) {
6565
Type[] types = controllerMethod.getGenericParameterTypes();
6666
ParameterizedType continuation = (ParameterizedType) types[types.length - 1];
6767
genericReturnType = ((WildcardType) continuation.getActualTypeArguments()[0]).getLowerBounds()[0];

spring-aot/src/test/java/org/springframework/aot/context/bootstrap/generator/infrastructure/nativex/NativeConfigurationUtilsTests.java

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,20 @@
2222
import java.util.Map;
2323
import java.util.Set;
2424

25+
import kotlin.Metadata;
26+
import kotlin.coroutines.Continuation;
2527
import org.junit.jupiter.api.Test;
2628

2729
/**
2830
* Tests for {@link NativeConfigurationUtils}.
2931
*
3032
* @author Andy Clement
33+
* @author Sebastien Deleuze
3134
*/
3235
class NativeConfigurationUtilsTests {
3336

3437
@Test
35-
public void typesInSignature() throws NoSuchMethodException, SecurityException, NoSuchFieldException {
38+
public void typesInSignatureForMethods() throws NoSuchMethodException, SecurityException, NoSuchFieldException {
3639
Set<Class<?>> collected = NativeConfigurationUtils.collectTypesInSignature(this.getClass().getDeclaredMethod("one"));
3740
assertThat(collected).containsOnly(Foo.class);
3841
collected = NativeConfigurationUtils.collectTypesInSignature(this.getClass().getDeclaredMethod("two", Foo.class));
@@ -41,9 +44,20 @@ public void typesInSignature() throws NoSuchMethodException, SecurityException,
4144
assertThat(collected).containsOnly(List.class, Foo.class);
4245
collected = NativeConfigurationUtils.collectTypesInSignature(this.getClass().getDeclaredMethod("four", Integer.TYPE, List.class, Map.class));
4346
assertThat(collected).containsOnly(Map.class, String.class, List.class, Foo.class, Bar.class, Integer.class);
44-
collected = NativeConfigurationUtils.collectTypesInSignature(Boo.class.getDeclaredField("foos"));
47+
}
48+
49+
@Test
50+
public void typesInSignatureForFields() throws NoSuchMethodException, SecurityException, NoSuchFieldException {
51+
Set<Class<?>> collected = NativeConfigurationUtils.collectTypesInSignature(Boo.class.getDeclaredField("foos"));
4552
assertThat(collected).containsOnly(List.class,Foo.class);
4653
}
54+
55+
@Test
56+
public void typesInSignatureForSuspendingMethods() throws NoSuchMethodException, SecurityException, NoSuchFieldException {
57+
Set<Class<?>> collected = NativeConfigurationUtils.collectTypesInSignature(Baz.class.getDeclaredMethod("greet", Continuation.class));
58+
assertThat(collected).containsOnly(Bar.class);
59+
}
60+
4761

4862
static class Foo {
4963

@@ -71,4 +85,11 @@ static class Boo {
7185
List<Foo> foos;
7286
}
7387

88+
@Metadata
89+
static class Baz {
90+
Object greet(Continuation<? super Bar> completion) {
91+
return null;
92+
}
93+
}
94+
7495
}

0 commit comments

Comments
 (0)