WALA
WALA copied to clipboard
ArgumentTypeEntrypoint doesn't ensure that chooseAnImplementor returns a concrete class
private TypeReference chooseAnImplementor(IClass iface) {
Set<IClass> implementors = cha.getImplementors(iface.getReference());
if (!implementors.isEmpty()) {
return implementors.iterator().next().getReference();
} else {
return null;
}
}
May return an IClass which is also an interface. I have a local version of this which is
private Optional<TypeReference> findAnImplementor(@NonNull final IClass interfaceClass) {
return getImplementors(interfaceClass).findFirst();
}
/** Fixed implementation which returns all implementing classes */
private Stream<TypeReference> getImplementors(@NonNull final IClass interfaceClass) {
return cha
.getImplementors(interfaceClass.getReference())
.stream()
.flatMap(implementor -> implementor.isInterface()
? getImplementors(implementor)
: Stream.of(implementor.getReference()));
}
Thanks @mattkindy-praetorian! Do you want to open a PR with your fix?