Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ClassInfoList.getClassesImplementing() throws exception if underlying object is a class despite documentation stating the contrary #543

Closed
parttimenerd opened this issue Aug 10, 2021 · 3 comments

Comments

@parttimenerd
Copy link

The documentation and the code differ for ClassInfoList.getClassesImplementing():

    /**
     * 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.
     */
    public ClassInfoList getClassesImplementing() {
        if (!isInterface()) {
            throw new IllegalArgumentException("Class is not an interface: " + getName());
        }

The code clearly throws an IllegalArgumentException for non-interfaces.

This propagates to ScanResult.getClassesImplementing() too which therefore has the same issue.

@lukehutch
Copy link
Member

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.

@parttimenerd
Copy link
Author

parttimenerd commented Aug 10, 2021

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.

@lukehutch
Copy link
Member

Fixed and released in 4.8.113. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants