You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
/** * Get the classes (and their subclasses) that implement this interface, if this is an interface. * * @return the list of the classes (and their subclasses) that implement this interface, if this is an * interface, otherwise returns the empty list. */publicClassInfoListgetClassesImplementing() {
if (!isInterface()) {
thrownewIllegalArgumentException("Class is not an interface: " + getName());
}
The code clearly throws an IllegalArgumentException for non-interfaces.
Thanks, good catch. Do you think this should throw an exception, or just return the empty list? The argument for throwing an exception is that it may help find bugs in a user's code, but maybe it is better never to throw exceptions, and fail gracefully instead.
I would personally prefer the latter. My current use case (where this came up) is getting all implementing classes and subclasses for a ClassInfo object (not caring about the distinction between interfaces and classes).
A preliminary search on GitHub for usages of the method shows that most usages are in the context where the ClassInfo object is expected to be an interface.
The documentation and the code differ for
ClassInfoList.getClassesImplementing()
:The code clearly throws an
IllegalArgumentException
for non-interfaces.This propagates to
ScanResult.getClassesImplementing()
too which therefore has the same issue.The text was updated successfully, but these errors were encountered: