dimanche 21 mars 2021

Java Reflections Library - Class loader warnings about unrelated classes

I'm using the Reflections library to get all classes annotated by a specific annotation in a specific package.

IndexSpec annotation

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface IndexSpec {
    String value();
}

Annotated class

@IndexSpec("connected_clients")
public class ConnectedClients implements ElasticIndex {
    [...]
}

Reflection

[...]

var reflections = new Reflections(new ConfigurationBuilder()
        .setUrls(ClasspathHelper.forPackage("a.b.c.indices")) // Package name redacted for legal reasons
        .setScanners(new SubTypesScanner(), new TypeAnnotationsScanner()));

var annotatedIndices = reflections.getTypesAnnotatedWith(IndexSpec.class);

[...]

This code works fine but I get a large amount of warnings. There is are a few hundred of them for many of different, unrelated classes.

Reflections says it found a lot of classes in a package that contains exactly two classes.

Reflections took 2303 ms to scan 1 urls, producing 2898 keys and 11715 values

The warnings all look like this:

[org.reflections.Reflections] could not get type for name com.fasterxml.jackson.databind.ObjectMapper from any class loader

Why is the library scanning classes in a different package than what it was configured for?





Aucun commentaire:

Enregistrer un commentaire