Skip to content

JavaType#getAllInvolvedRawTypes() throws StackOverflowError with self-referential generic types #1237

@rashtao

Description

@rashtao

JavaType#getAllInvolvedRawTypes() throws StackOverflowError when invoked on a self-referential generic type.

The problem can be reproduced with the following code snippet:

import com.tngtech.archunit.base.DescribedPredicate;
import com.tngtech.archunit.core.domain.JavaMethod;
import com.tngtech.archunit.core.importer.ClassFileImporter;

import static com.tngtech.archunit.lang.conditions.ArchConditions.be;
import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.methods;

public abstract class Foo<T extends Foo<T>> {
    public abstract T getThis();

    public static void main(String[] args) {
        methods()
                .should(be(new DescribedPredicate<JavaMethod>("allInvolvedRawTypes") {
                    @Override
                    public boolean test(JavaMethod m) {
                        return m.getReturnType().getAllInvolvedRawTypes().stream().allMatch(alwaysTrue());
                    }
                }))
                .check(new ClassFileImporter().importClasses(Foo.class));
    }
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions