diff --git a/rewrite-java-test/src/main/java/org/openrewrite/java/JavaTypeMappingTest.java b/rewrite-java-test/src/main/java/org/openrewrite/java/JavaTypeMappingTest.java index 591d897bfc3..3783a9365cf 100644 --- a/rewrite-java-test/src/main/java/org/openrewrite/java/JavaTypeMappingTest.java +++ b/rewrite-java-test/src/main/java/org/openrewrite/java/JavaTypeMappingTest.java @@ -110,6 +110,11 @@ default void generic() { assertThat(generic.getName()).isEqualTo("?"); assertThat(generic.getVariance()).isEqualTo(COVARIANT); assertThat(TypeUtils.asFullyQualified(generic.getBounds().get(0)).getFullyQualifiedName()).isEqualTo("org.openrewrite.java.C"); + + generic = (JavaType.GenericTypeVariable) TypeUtils.asParameterized(methodType("generic").getReturnType()).getTypeParameters().get(0); + assertThat(generic.getName()).isEqualTo("?"); + assertThat(generic.getVariance()).isEqualTo(COVARIANT); + assertThat(TypeUtils.asFullyQualified(generic.getBounds().get(0)).getFullyQualifiedName()).isEqualTo("org.openrewrite.java.C"); } @Test diff --git a/rewrite-java/src/main/java/org/openrewrite/java/internal/JavaReflectionTypeMapping.java b/rewrite-java/src/main/java/org/openrewrite/java/internal/JavaReflectionTypeMapping.java index a7fb142280a..440217560b4 100644 --- a/rewrite-java/src/main/java/org/openrewrite/java/internal/JavaReflectionTypeMapping.java +++ b/rewrite-java/src/main/java/org/openrewrite/java/internal/JavaReflectionTypeMapping.java @@ -472,13 +472,13 @@ private JavaType.Method method(Method method, JavaType.FullyQualified declaringT List parameterTypes = emptyList(); if (method.getParameters().length > 0) { parameterTypes = new ArrayList<>(method.getParameters().length); - for (Parameter parameter : method.getParameters()) { - Type parameterizedType = parameter.getParameterizedType(); - parameterTypes.add(type(parameterizedType == null ? parameter.getType() : parameterizedType)); + for (Type parameter : method.getGenericParameterTypes()) { + parameterTypes.add(type(parameter)); } } - mappedMethod.unsafeSet(declaringType, type(method.getReturnType()), parameterTypes, thrownExceptions, annotations); + JavaType returnType = type(method.getGenericReturnType()); + mappedMethod.unsafeSet(declaringType, returnType, parameterTypes, thrownExceptions, annotations); return mappedMethod; } }