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

Updating from 0.9.8 to 0.9.12 breaks #277

Closed
SElab2019 opened this issue Jan 20, 2020 · 6 comments
Closed

Updating from 0.9.8 to 0.9.12 breaks #277

SElab2019 opened this issue Jan 20, 2020 · 6 comments

Comments

@SElab2019
Copy link

When I try to upgrade reflections from 0.9.8 to the version after 0.9.9. The following code breaks.

import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;

import javax.persistence.Entity;

import org.hibernate.cfg.Configuration;
import org.hibernate.dialect.Oracle10gDialect;
import org.hibernate.tool.hbm2ddl.SchemaExport;
import org.junit.Test;
import org.reflections.Reflections;
import org.reflections.scanners.TypeAnnotationsScanner;
import org.reflections.util.ClasspathHelper;
import org.reflections.util.ConfigurationBuilder;


public class SchemaFromScratchTest {

	public static final String ORACLE_DIALECT = Oracle10gDialect.class.getCanonicalName();
	public static final String CREATE_FILE_NAME = "./target/classes/sql/create_schema_from_scratch.sql";
	public static final String PACKAGE = "valtech.dbdiff.model";
	public static final int LAST_MODIFIED_PRECISION = 999;

	@Test
	public void generateCreate() throws ClassNotFoundException {
		final long now = System.currentTimeMillis() - LAST_MODIFIED_PRECISION;
		final Configuration cfg = new Configuration();
		cfg.setProperty("hibernate.hbm2ddl.auto", "create");
		cfg.setProperty("hibernate.dialect", ORACLE_DIALECT);

		for (final String className : findEntities()) {
			cfg.addAnnotatedClass(Class.forName(className));
		}

		final SchemaExport export = new SchemaExport(cfg);
		export.setDelimiter(";");
		export.setOutputFile(CREATE_FILE_NAME);
		export.execute(true, false, false, true);
		File file = new File(CREATE_FILE_NAME);
	}

	private List<String> findEntities() {
		final ConfigurationBuilder c = new ConfigurationBuilder();
		c.setUrls(ClasspathHelper.forPackage(PACKAGE));
		c.setScanners(new TypeAnnotationsScanner());
		final Reflections reflections = new Reflections(c);
		final Set<Class<?>> entities = reflections.getTypesAnnotatedWith(Entity.class);
		final List<String> entityClassNameList = new ArrayList<String>(entities.size());
		for (final Class<?> entity : entities) {
			entityClassNameList.add(entity.getName());
		}
		return entityClassNameList;
	}
}

The code should pass, but it throws an error:

org.reflections.ReflectionsException: Scanner SubTypesScanner was not configured
	at org.reflections.Store.get(Store.java:58)
	at org.reflections.Store.get(Store.java:70)
	at org.reflections.Store.getAll(Store.java:97)
	at org.reflections.Reflections.getAllAnnotated(Reflections.java:423)
	at org.reflections.Reflections.getTypesAnnotatedWith(Reflections.java:384)
	at org.reflections.Reflections.getTypesAnnotatedWith(Reflections.java:370)
	at SchemaFromScratchTest.findEntities(SchemaFromScratchTest.java:54)
	at SchemaFromScratchTest.generateCreate(SchemaFromScratchTest.java:37)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:89)
	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:41)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:541)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:763)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:463)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:209)
@alexlember
Copy link

Experiencing same issue.

Trace:

exception; nested exception is org.reflections.ReflectionsException: Scanner SubTypesScanner was not configured at 
org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185) at 
org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:640) ... 54 common frames omittedCaused by: org.reflections.ReflectionsException: Scanner SubTypesScanner was not configured at org.reflections.Store.get(Store.java:39) at 
org.reflections.Store.get(Store.java:61) at org.reflections.Store.get(Store.java:46) at 
org.reflections.Store.getAll(Store.java:93) at 
org.reflections.Reflections.getSubTypesOf(Reflections.java:404) at 

Code:

public static <T> Stream<Class<? extends T>> discover(Class<T> businessEntityType) {
        Reflections reflections = new Reflections(BUSINESS_ENTITY_PACKAGE);
        return reflections.getSubTypesOf(businessEntityType).stream()
                .filter(type -> EXCLUDE_ENTITY_PACKAGES.stream().noneMatch(p -> type.getName().startsWith(p)))
                .filter(type -> !Modifier.isAbstract(type.getModifiers()))
                .map(type -> type.asSubclass(businessEntityType));
    }

@alexlember
Copy link

Does anyone know how to make it works in spring boot for fat jar?

Current output:
2020-02-04 12:29:48.822 INFO 17788 --- [actor-tcp-nio-1] org.reflections.Reflections : Reflections took 13 ms to scan 1 urls, producing 0 keys and 0 values
2020-02-04 12:29:48.825 ERROR 17788 --- [actor-tcp-nio-1] r.p.primeconnect.client.json.JSONClient : Scanner SubTypesScanner was not configured

Seems like it doesn't see any class in provided package. Upgraded from 0.9.11 to 0.9.12.

@porunov
Copy link

porunov commented Mar 6, 2020

Same issue. The bug was introduced in 0.9.12 version. Use 0.9.11 till it is fixed.

The bug was introduced here:
937c8f3#r37682143

@ldebello
Copy link

I think the issue is not there I was debugging and it is having issue to get the inputstream from the jar file, in the class AbstractScanner try { classObject = configuration.getMetadataAdapter().getOrCreateClassObject(file); } catch (Exception e) { throw new ReflectionsException("could not create class object from file " + file.getRelativePath(), e); }

that is failing so it cannot read the class and it cannot add the scanner to the store which is what it does in the scan method of SubTypesScanner

jpdigital pushed a commit to jpdigital/hibernate5-ddl-maven-plugin that referenced this issue Jun 17, 2020
vincenzopalazzo added a commit to clightning4j/JRPClightning that referenced this issue Apr 26, 2021
The bug of reflections library is described here ronmamo/reflections#277

Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
mueller-ma added a commit to openhab/openhab-android that referenced this issue Aug 28, 2021
There's a bug at org.reflections: ronmamo/reflections#277

Signed-off-by: mueller-ma <mueller-ma@users.noreply.github.com>
mueller-ma pushed a commit to openhab/openhab-android that referenced this issue Aug 29, 2021
Bumps gradle from 4.2.2 to 7.0.1.

---
updated-dependencies:
- dependency-name: com.android.tools.build:gradle
  dependency-type: direct:production
  update-type: version-update:semver-major
...

* Update Android Studio and update to Java 11
* Update UnMockPlugin
* Remove TileServicesTests

There's a bug at org.reflections: ronmamo/reflections#277

* Disable daemon

Signed-off-by: mueller-ma <mueller-ma@users.noreply.github.com>
@ronmamo
Copy link
Owner

ronmamo commented Sep 25, 2021

apologize for this annoyance.

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants