ArchUnit
ArchUnit copied to clipboard
JavaType#getAllInvolvedRawTypes() throws StackOverflowError with self-referential generic types
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));
}
}
Thanks for reporting! You're right that this is a bug 🙈 I'm gonna try to fix it as soon as I can find some free time to focus (spontaneously I'm not sure without introducing unwanted public API...)
(if anybody else has more time available feel free to grab this)