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

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

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 48
  • Comments: 25 (2 by maintainers)

Commits related to this issue

Most upvoted comments

Guys please be aware that we are on an open source platform and this developer did some free work so you don’t have to do it yourself. I also wait for a fix, but we do not know the circumstances why the developer is currently not as responsive as in the past(maybe he currently does a world trip or has personal issues, how knows).

There are currently 569 forks of this project, maybe someone has already found a fix or you can fork it yourself and investigate it. Or you can try https://github.com/aschoerk/reflections8 as suggested above.

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?

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.

This is a shame. A library that’s this widely used should at least be handed over to someone else who wants to maintain it

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.

fixed on 0.10

This has been broken for over nine months by now… @ronmamo can we get a bugfix release 0.9.13 or is this library considered abandoned?

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

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 ?

Seems like there is no maintainer active anymore, might be time to fork this repo and start merging the pull requests that started to pile up with release on maven central.

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);
	}
   }
}

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