Skip to content

Commit

Permalink
Fix stackoverflow with generics. Fixes micronaut-projects#2239
Browse files Browse the repository at this point in the history
  • Loading branch information
graemerocher committed Oct 17, 2019
1 parent fa7d3b9 commit 734e295
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,15 @@ protected Map<String, Object> resolveGenericTypes(DeclaredType type, TypeElement
if (extendsBound != null) {
resolveGenericTypeParameter(resolvedParameters, parameterName, extendsBound, boundTypes);
} else if (superBound != null) {
resolveGenericTypeParameter(resolvedParameters, parameterName, superBound, boundTypes);
if (superBound instanceof TypeVariable) {
TypeVariable superTypeVar = (TypeVariable) superBound;
final TypeMirror upperBound = superTypeVar.getUpperBound();
if (upperBound != null && !type.equals(upperBound)) {
resolveGenericTypeParameter(resolvedParameters, parameterName, superBound, boundTypes);
}
} else {
resolveGenericTypeParameter(resolvedParameters, parameterName, superBound, boundTypes);
}
} else {
resolvedParameters.put(parameterName, Object.class);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,25 @@ import java.util.function.Function

class GenericTypeArgumentsSpec extends AbstractTypeElementSpec {

void "test recusive generic type parameter"() {
given:
BeanDefinition definition = buildBeanDefinition('test.TrackedSortedSet','''\
package test;
import io.micronaut.inject.annotation.*;
import io.micronaut.context.annotation.*;
@javax.inject.Singleton
final class TrackedSortedSet<T extends java.lang.Comparable<? super T>> {
public TrackedSortedSet(java.util.Collection<? extends T> initial) {
super();
}
}
''')
expect:
definition != null
}

void "test type arguments for interface"() {
given:
Expand Down

0 comments on commit 734e295

Please sign in to comment.