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

After migrating to 0.9.12, Getting exception : org.reflections.RflectionException: Scanner SubTypeScanner was not configured , even after configuring the scanner. #273

Closed
anandmnair opened this issue Jan 9, 2020 · 25 comments

Comments

@anandmnair
Copy link

I was using 0.9.11 and with scanners it was working fine. but by just changing the version to 0.9.12 , stared getting the exception for "org.reflections.RflectionException: Scanner SubTypeScanner was not configured".

Reflections reflections = new Reflections(new ConfigurationBuilder()
     .setUrls(ClasspathHelper.forPackage("my.project.prefix"))
     .setScanners(new SubTypesScanner(), new TypeAnnotationsScanner()),
     .filterInputsBy(new FilterBuilder().includePackage("my.project.prefix"))
     );

reflections.getSubTypesOf(someClass);  // here it throws exception 

I noticed that, when I add a class which extend some class to the package, this error goes.
Same with FieldAnnotationScanner , or any other scanner.

To try , please provide an invalid package for reflection creation, you will see all these errors coming even after configuring all scanners with reflection

@azell
Copy link

azell commented Jan 17, 2020

Having an enum type in the package path will also fix the problem, as it will force SubTypesScanner to be invoked.

@aheritier
Copy link

Same problem for me. Not sure if it's a regression of if I should adapt some code

@azell
Copy link

azell commented Jan 18, 2020

Think removing store.getOrCreate method is the culprit.

@koppor
Copy link

koppor commented Jan 19, 2020

Same issue for ResourcesScanner (e.g., example from
https://github.com/ronmamo/reflections/blob/gh-pages/UseCases.md#find-resources-in-your-classpath)

Or

    Reflections reflections = new Reflections(new ResourcesScanner());
    var resources = reflections.getResources(Pattern.compile(".*pom\\.xml"));
Exception in thread "main" org.reflections.ReflectionsException: Scanner ResourcesScanner was not configured

Does not happen with 0.9.11.

@chia7712
Copy link

Think removing store.getOrCreate method is the culprit.

+1

    public Reflections(final Configuration configuration) {
        this.configuration = configuration;
        store = new Store(configuration);

        if (configuration.getScanners() != null && !configuration.getScanners().isEmpty()) {
            //inject to scanners
            for (Scanner scanner : configuration.getScanners()) {
                scanner.setConfiguration(configuration);
                scanner.setStore(store.getOrCreate(scanner.getClass().getSimpleName())); // this line
            }

            scan();

            if (configuration.shouldExpandSuperTypes()) {
                expandSuperTypes();
            }
        }
    }

In 0.9.11, the constructor adds collection of all configured scanners to Store before does scan classes. By contrast, 0.9.12 create collection of all configured scanners only if it does scan something successfully. Personally, the error "was not configured" happening in 0.9.12 is a litter weird since the scanner is indeed "configured".

Could we keep the behavior of 0.9.11 (pre-create collection for all configured scanners) to fix this issue ?

@tmortagne
Copy link

Same issue here with ResourcesScanner.

Works fine when resource are found but crashing when there is nothing matching the configuration.
Looks like when no resource is found matching the configuration the corresponding map is null instead of being empty which make Store#get(String) think (wrongly) that this scanner was not even configured.

kkonstantine pushed a commit to apache/kafka that referenced this issue Mar 16, 2020
…8289)

This commit works around a bug in version v0.9.12 of the upstream `reflections` library by catching and handling the exception thrown.

The reflections issue is tracked by:
ronmamo/reflections#273

New unit tests were introduced to test the behavior.

* KAFKA-9712: Catch and handle exception thrown by reflections scanner

* Update connect/runtime/src/main/java/org/apache/kafka/connect/runtime/isolation/DelegatingClassLoader.java

Co-Authored-By: Konstantine Karantasis <konstantine@confluent.io>

* Move result initialization back to right before it is used

* Use `java.io.File` in tests

* Fix checkstyle

Co-authored-by: Konstantine Karantasis <konstantine@confluent.io>

Reviewers: Konstantine Karantasis <konstantine@confluent.io>, Chia-Ping Tsai <chia7712@gmail.com>
kkonstantine pushed a commit to apache/kafka that referenced this issue Mar 16, 2020
…8289)

This commit works around a bug in version v0.9.12 of the upstream `reflections` library by catching and handling the exception thrown.

The reflections issue is tracked by:
ronmamo/reflections#273

New unit tests were introduced to test the behavior.

* KAFKA-9712: Catch and handle exception thrown by reflections scanner

* Update connect/runtime/src/main/java/org/apache/kafka/connect/runtime/isolation/DelegatingClassLoader.java

Co-Authored-By: Konstantine Karantasis <konstantine@confluent.io>

* Move result initialization back to right before it is used

* Use `java.io.File` in tests

* Fix checkstyle

Co-authored-by: Konstantine Karantasis <konstantine@confluent.io>

Reviewers: Konstantine Karantasis <konstantine@confluent.io>, Chia-Ping Tsai <chia7712@gmail.com>
@GodLiang
Copy link

I also have this problem.I wan to change another lib.

@porunov
Copy link

porunov commented Apr 15, 2020

We just switched to https://github.com/aschoerk/reflections8 (version 0.11.7). Even so it says that it is obsolete after reflections 0.9.12 release, they don't have this bug.
The fix to this issue is provided here: #278 but it wasn't reviewed / merged by repository maintainers.

@tr7zw
Copy link

tr7zw commented May 28, 2020

What's the status here? This is a breaking issue that's been open for 5-6 months now, and the pr to fix it got closed without an update?

@TanVD
Copy link

TanVD commented Jun 2, 2020

Any updates? It is really strange that PR with fix of a problem was closed even without a comment.

@mfvanek
Copy link

mfvanek commented Jul 2, 2020

I've faced with the same bug. Migrated to reflections8

@dano
Copy link

dano commented Jul 24, 2020

I haven't tested it to confirm, but it looks like @ronmamo might have fixed this via #275 on April 26th, the same day the PR that someone provided here was closed without comment.

@AntonOyung
Copy link

AntonOyung commented Aug 7, 2020

I upgraded 2 days ago from 0.9.11 to 0.9.12 and I am still seeing this issue

@dano
Copy link

dano commented Aug 7, 2020

Just to clarify my previous comment - you'd have to be using 0.9.13-SNAPSHOT to have the commit I think may have fixed it.

@AntonOyung
Copy link

How can I get 0.9.13-SNAPSHOT?

@dano
Copy link

dano commented Aug 10, 2020

@AntonOyung I think you'll have to build it from source yourself. It doesn't look like SNAPSHOT builds get pushed to a maven repository.

@xresch
Copy link

xresch commented Sep 1, 2020

I ran into the same issue when migrating from JDK8 to JDK11.
For me the issue didn't occur anymore when I removed the configuration builder and just instantiated the Reflections class like below.
This way works for me for JDK 8, 11 and 13 and with reflection version 0.9.12.

//-------------------------------------------
// Old instantiation that throws an error with 
// reflections 0.9.12 and JDK 11 or higher

//       Reflections reflections = new Reflections(new ConfigurationBuilder()
//            //.filterInputsBy(new FilterBuilder().exclude(FilterBuilder.prefix("com.xresch.cfw.")))
//            .filterInputsBy(new FilterBuilder().exclude(FilterBuilder.prefix("java.")))
//            .setUrls(ClasspathHelper.forClassLoader())
//            //.setScanners(new SubTypesScanner(), new TypeAnnotationsScanner())
//       );
	
//-------------------------------------------
// New instantiation that works with 
// Reflections 0.9.12 and JDK8 or higher
// scans all classes	
Reflections reflections = new Reflections("");

//-------------------------------------------
// No changes here
Set<Class<?>> types = reflections.getTypesAnnotatedWith(CFWExtensionApplication.class);

for(Class<?> clazz : types) {
   if(CFWAppInterface.class.isAssignableFrom(clazz)) {
	   new CFWLog(logger).method("loadExtentionApplication").info("Load CFW Extension Application:"+clazz.getName());
	   
	  try {
		CFWAppInterface instance = (CFWAppInterface)clazz.newInstance();
		return instance;
	} catch (InstantiationException | IllegalAccessException e) {
		new CFWLog(logger).method("loadExtentionApplication").severe("Error loading CFW Extension Application:"+clazz.getName(), e);
	}
   }
}

hubertp added a commit to ShiftLeftSecurity/overflowdb that referenced this issue Sep 18, 2020
Apparently I'm able to invoke our codepropertygraph's console via a path
that triggers ronmamo/reflections#273.
This is very unfortunate and due to the way the artifact is being
publishes I'm unable to downgrade directly in the project I use.

The fix is in 0.9.13-SNAPSHOT (not yet released) so suggestig to
downgrade until it is officially out.
andrewegel pushed a commit to confluentinc/kafka that referenced this issue May 25, 2021
…pache#8289)

This commit works around a bug in version v0.9.12 of the upstream `reflections` library by catching and handling the exception thrown.

The reflections issue is tracked by:
ronmamo/reflections#273

New unit tests were introduced to test the behavior.

* KAFKA-9712: Catch and handle exception thrown by reflections scanner

* Update connect/runtime/src/main/java/org/apache/kafka/connect/runtime/isolation/DelegatingClassLoader.java

Co-Authored-By: Konstantine Karantasis <konstantine@confluent.io>

* Move result initialization back to right before it is used

* Use `java.io.File` in tests

* Fix checkstyle

Co-authored-by: Konstantine Karantasis <konstantine@confluent.io>

Reviewers: Konstantine Karantasis <konstantine@confluent.io>, Chia-Ping Tsai <chia7712@gmail.com>
imonteroperez added a commit to imonteroperez/plugin-compat-tester that referenced this issue Sep 10, 2021
imonteroperez added a commit to imonteroperez/plugin-compat-tester that referenced this issue Sep 13, 2021
@ronmamo
Copy link
Owner

ronmamo commented Sep 25, 2021

apologize for this inconvenience !

scanner was not configured exception - this is a known issue in 0.9.12, a simple workaround is to check if the getStore() contains index for the scanner before querying. next version 0.10 fixes this.

@ronmamo
Copy link
Owner

ronmamo commented Oct 4, 2021

fixed on 0.10

@ronmamo ronmamo closed this as completed Oct 4, 2021
Bajzathd added a commit to hortonworks/cloudbreak that referenced this issue Mar 23, 2022
Increment reflections version, as DomainToStringTest was affected by this bug: ronmamo/reflections#273
Bajzathd added a commit to hortonworks/cloudbreak that referenced this issue Mar 23, 2022
Increment reflections version, as DomainToStringTest was affected by this bug: ronmamo/reflections#273
Bajzathd added a commit to hortonworks/cloudbreak that referenced this issue Mar 23, 2022
Increment reflections version, as DomainToStringTest was affected by this bug: ronmamo/reflections#273
uw4 added a commit to dashjoin/platform that referenced this issue May 31, 2022
neofreko pushed a commit to neofreko/graphwalker-project that referenced this issue Aug 9, 2022
While also:
1. Upgrade reflection library due to ronmamo/reflections#273
2. Memoized list of classloaders as it's getting called on each processed file.
3. Added tests for SimpleCache
4. Added tests CodeGenerator fix
5. Minor adjustments
mlsorensen added a commit to mlsorensen/cloudstack that referenced this issue Sep 28, 2023
mlsorensen added a commit to apache/cloudstack that referenced this issue Sep 28, 2023
Addresses bug described in reflections 0.9.12 ronmamo/reflections#273
DaanHoogland pushed a commit to apache/cloudstack that referenced this issue Oct 16, 2023
Addresses bug described in reflections 0.9.12 ronmamo/reflections#273
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.