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

0.10.2 ConfigurationBuilder.build() doesn't accept parameters correctly #401

Open
veselov opened this issue Jun 17, 2022 · 1 comment
Open

Comments

@veselov
Copy link

veselov commented Jun 17, 2022

ConfigurationBuilder.java:

Input parameters are in params
Lines 71-76 - a new list parameters is created, where the normalized parameters are supposed to go, anything iterable or any arrays in params are expanded as individual items into parameters, everything else is copied as is.

Then, lines 78-79, all class loaders found in params are added with addClassLoaders() to the builder. Why "params", and not "parameters"?, AFAIU, this should go over "parameters".

Then, lines 84-101, the individual parameters are processed for usage. Anything that is not recognized causes a ReflectionsException to be thrown. ClassLoaders are not recognized as parameters at this point, so if any found in parameters, the method throws. Since nothing cleaned the class loaders from the parameters adding an instance of a classLoader to the parameters just throws.

IMHO, classloaders should be checked in the "if" chain that's on lines 84-101, and plainly ignored.

@mpscholz
Copy link

mpscholz commented Aug 1, 2022

Same issue here: In case one uses a classloader parameter in the build() method of the ConfigurationBuilder, a ReflectionException is thrown:

ConfigurationBuilder.build("my.package", this.getClass.getClassLoader())

will throw
org.reflections.ReflectionsException: could not use param

This is due to the fact, that the implementation of the ConfigurationBuilder.build() method in org.reflections 0.10.2 correctly identifies the classloader param and adds it to the internal list of classloaders, but does not remove them from the internal list of parameters; as a consequence, the subsequent if-else instanceof cascade runs into the final fallback branch that throws a ReflectionException.

Mind that this is a rather annoying bug since it breaks code that worked flawlessly in org.reflections 0.9.12.

Workaround: use

ConfigurationBuilder.build().addClassLoaders(classloaders).forPackage(pacḱage)
instead.

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