Giter Site home page Giter Site logo

Comments (3)

moldowan avatar moldowan commented on July 30, 2024

Have you read https://github.com/lukehutch/fast-classpath-scanner#detecting-annotations-superclasses-and-implemented-interfaces-outside-of-whitelisted-packages ?

While this explains the problem, I would rather just use MatchProcessors right away instead of having to collect the results afterwards and having to load the classes myself.
There has been a discussion before in #30

from classgraph.

czyzby avatar czyzby commented on July 30, 2024

Still, this seems rather unnecessary that you have to whitelist both the interface and all abstract classes that might be extended by your scanned types. While whitelisting all abstract classes is certainly an option, I'd expect the scanner to find _all_ classes implementing the chosen interface (even if indirectly), regardless of the location of the possible supertypes.

from classgraph.

lukehutch avatar lukehutch commented on July 30, 2024

(Rather unfortunately) this is intended behavior, because to discover that ConcreteSearched implements Searched, you either have to scan both Searched and AbstractSearched (which defeats the original goal of searching only the package containing ConcreteSearched), or you have to call the classloader on either ConcreteSearched, or AbstractSearched, so that you can see these classes implement Searched (which defeats the whole point of FastClasspathScanner parsing the classfile binary format directly).

There is no reasonable way to fix this in FastClasspathScanner without entirely changing how FastClasspathScanner works, so that it calls the ClassLoader on each scanned class, which would be bad.

The right way to fix this in your code is to increase the coverage of the scan spec whitelist. Note that (as described in the link provided by mdolwan@) you can whitelist specific classes by name, not just packages, so in this case you can just call:

    new FastClasspathScanner(
            "package.containing.concretesearched",
            "otherpackage.Searched",
            "otherpackage.AbstractSearched").scan()

You said: "I'd expect the scanner to find all classes implementing the chosen interface (even if indirectly), regardless of the location of the possible supertypes." FastClasspathScanner does exactly that, as long as those classes are on a whitelisted path.

If you don't want to whitelist a path, you can just call FastClasspathScanner without any parameters (or with an empty path), and it will scan the entire classpath:

    new FastClasspathScanner("").scan()

Sorry I don't have a better fix than this (and have to mark this as closed), but calling the classloader while scanning is your enemy in the general case (class loading is time-consuming, and can trigger arbitrary static initializer code to run).

Keep the suggestions coming though, thanks for the report.

from classgraph.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.