WALA icon indicating copy to clipboard operation
WALA copied to clipboard

ArgumentTypeEntrypoint doesn't ensure that chooseAnImplementor returns a concrete class

Open mattkindy opened this issue 5 years ago • 1 comments

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()));
}

mattkindy avatar Feb 07 '20 18:02 mattkindy

Thanks @mattkindy-praetorian! Do you want to open a PR with your fix?

msridhar avatar Feb 07 '20 21:02 msridhar