reflections icon indicating copy to clipboard operation
reflections copied to clipboard

Warning "could not create Vfs.Dir from url" pollutes log, when using ClasspathHelper.forClassLoader()

Open ge0ffrey opened this issue 9 years ago • 17 comments

Here's the code I used: ConfigurationBuilder builder = new ConfigurationBuilder(); builder.addUrls(ClasspathHelper.forClassLoader()); Reflections reflections = new Reflections(builder);

And I get this ugly warning in my log:

11:23:59,868 WARN [org.reflections.Reflections](default task-9) could not create Vfs.Dir from url. ignoring the exception and continuing: org.reflections.ReflectionsException: could not create Vfs.Dir from url, no matching UrlType was found [file:/usr/lib/jvm/java-7-openjdk-i386/jre/lib/ext/libatk-wrapper.so] either use fromURL(final URL url, final List<UrlType> urlTypes) or use the static setDefaultURLTypes(final List<UrlType> urlTypes) or addDefaultURLTypes(UrlType urlType) with your specialized UrlType. at org.reflections.vfs.Vfs.fromURL(Vfs.java:109) [reflections-0.9.10.jar:] at org.reflections.vfs.Vfs.fromURL(Vfs.java:91) [reflections-0.9.10.jar:] at org.reflections.Reflections.scan(Reflections.java:237) [reflections-0.9.10.jar:] at org.reflections.Reflections.scan(Reflections.java:204) [reflections-0.9.10.jar:] at org.reflections.Reflections.(Reflections.java:129) [reflections-0.9.10.jar:]

Workaround: ConfigurationBuilder builder = new ConfigurationBuilder(); builder.addUrls(ClasspathHelper.forPackage("")); Reflections reflections = new Reflections(builder);

ge0ffrey avatar Jul 15 '15 09:07 ge0ffrey

Even I'm facing a similar issue. Here is my code:

Configuration config = new ConfigurationBuilder()
       .setScanners(new MethodAnnotationsScanner(), new SubTypesScanner())
       .addUrls(ClasspathHelper.forJavaClassPath());

And i get this warning in log:

[main] WARN  org.reflections.Reflections  - could not create Dir using directory from url file:/Users/apoorvam/twist/sahi%20project/sahi%20project/libs/com.thoughtworks.twist.driver.sahi_5.0.0.13827-fb7409160b2f96/sahi/docs/sahi_textpad.zip. skipping.
java.lang.RuntimeException: cannot use dir /Users/apoorvam/twist/sahi project/sahi project/libs/com.thoughtworks.twist.driver.sahi_5.0.0.13827-fb7409160b2f96/sahi/docs/sahi_textpad.zip
    at org.reflections.vfs.SystemDir.<init>(SystemDir.java:20)
    at org.reflections.vfs.Vfs$DefaultUrlTypes$3.createDir(Vfs.java:237)
    at org.reflections.vfs.Vfs.fromURL(Vfs.java:99)
    at org.reflections.vfs.Vfs.fromURL(Vfs.java:91)
    at org.reflections.Reflections.scan(Reflections.java:231)
    at org.reflections.Reflections.scan(Reflections.java:204)
    at org.reflections.Reflections.<init>(Reflections.java:129)

Using ClasspathHelper.forPackage() din't help. Is there a way to disable this?

apoorvam avatar Aug 13 '15 11:08 apoorvam

After finding this https://issues.apache.org/jira/browse/ISIS-805, I extracted a workaround from ClassDiscoveryServiceUsingReflections.java. It fixed my problem with .mar and .jnilib filetypes using org.reflections:reflections:0.9.10.

See ReflectionsHelper here: https://gist.github.com/nonrational/287ed109bb0852f982e8

@apoorvam you'll need to add sahi_textpad.zip to line 30. ~~@ge0ffrey looks like you'll need to add .so to line 30.~~ Sorry. I missed that you'd already found a workaround.

nonrational avatar Sep 09 '15 16:09 nonrational

It would be nice if the original issue is fixed though, so I can remove the workaround :)

ge0ffrey avatar Sep 10 '15 07:09 ge0ffrey

+1

ghost avatar Sep 22 '15 13:09 ghost

Thats my stacktrace hope it helps on the fix

WARNING: could not create Vfs.Dir from url. ignoring the exception and continuing org.reflections.ReflectionsException: could not create Vfs.Dir from url, no matching UrlType was found [file:/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/ext/libatk-wrapper.so] either use fromURL(final URL url, final List<UrlType> urlTypes) or use the static setDefaultURLTypes(final List<UrlType> urlTypes) or addDefaultURLTypes(UrlType urlType) with your specialized UrlType. at org.reflections.vfs.Vfs.fromURL(Vfs.java:109) at org.reflections.vfs.Vfs.fromURL(Vfs.java:91) at org.reflections.Reflections.scan(Reflections.java:231) at org.reflections.Reflections.scan(Reflections.java:204) at org.reflections.Reflections.(Reflections.java:129) at org.reflections.Reflections.(Reflections.java:170)

hamilton-lima avatar Jan 18 '16 03:01 hamilton-lima

Based on @karelCemus workaround fixed with this:

Reflections reflections = new Reflections(new ConfigurationBuilder().setUrls(ClasspathHelper.forPackage(
				packageName, ClasspathHelper.contextClassLoader(),
				ClasspathHelper.staticClassLoader())) 
);

hamilton-lima avatar Nov 25 '16 18:11 hamilton-lima

+1

sawo avatar Dec 08 '16 13:12 sawo

+1 I think I've got the same. I do the following:

final Reflections childReflections = new Reflections(new ConfigurationBuilder().forPackages(packageName).useParallelExecutor());

and I get:

Caused by: org.reflections.ReflectionsException: could not create Vfs.Dir from url, no matching UrlType was found [war:file:/C:/workspace/nemesis-archetype/target/samplestore.war*/WEB-INF/cl
asses/]
either use fromURL(final URL url, final List<UrlType> urlTypes) or use the static setDefaultURLTypes(final List<UrlType> urlTypes) or addDefaultURLTypes(UrlType urlType) with your specialize
d UrlType.
        at org.reflections.vfs.Vfs.fromURL(Vfs.java:109)
        at org.reflections.vfs.Vfs.fromURL(Vfs.java:91)
        at org.reflections.Reflections.scan(Reflections.java:237)
        at org.reflections.Reflections$1.run(Reflections.java:200)
        at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
        at java.util.concurrent.FutureTask.run(Unknown Source)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
        ... 1 more

but this exception is seen only on Windows. On Linux it all works fine.

ptahchiev avatar Jan 27 '17 13:01 ptahchiev

I have the same error

2017-06-19 22:17:51.123  INFO 28908 --- [    Test worker] org.reflections.Reflections              : Reflections took 22 ms to scan 1 urls, producing 6 keys and 8 values 
    2017-06-19 22:17:51.168  INFO 28908 --- [    Test worker] org.reflections.Reflections              : Reflections took 5 ms to scan 1 urls, producing 7 keys and 8 values 
    2017-06-19 22:17:51.173  INFO 28908 --- [    Test worker] org.reflections.Reflections              : Reflections took 2 ms to scan 1 urls, producing 5 keys and 5 values 
    2017-06-19 22:17:51.177  INFO 28908 --- [    Test worker] org.reflections.Reflections              : Reflections took 2 ms to scan 1 urls, producing 9 keys and 15 values 
    2017-06-19 22:17:51.187  INFO 28908 --- [    Test worker] org.reflections.Reflections              : Reflections took 8 ms to scan 2 urls, producing 16 keys and 61 values 
    2017-06-19 22:17:51.238  WARN 28908 --- [    Test worker] org.reflections.Reflections              : could not create Vfs.Dir from url. ignoring the exception and continuing

    org.reflections.ReflectionsException: could not create Vfs.Dir from url, no matching UrlType was found [file:/home/tomasz/dev/projects/shardis/shardis-query/build/resources/main]
    either use fromURL(final URL url, final List<UrlType> urlTypes) or use the static setDefaultURLTypes(final List<UrlType> urlTypes) or addDefaultURLTypes(UrlType urlType) with your specialized UrlType.
        at org.reflections.vfs.Vfs.fromURL(Vfs.java:109) ~[reflections-0.9.11.jar:na]
        at org.reflections.vfs.Vfs.fromURL(Vfs.java:91) ~[reflections-0.9.11.jar:na]
        at org.reflections.Reflections.scan(Reflections.java:240) [reflections-0.9.11.jar:na]
        at org.reflections.Reflections.scan(Reflections.java:202) [reflections-0.9.11.jar:na]
        at org.reflections.Reflections.<init>(Reflections.java:123) [reflections-0.9.11.jar:na]
        at org.reflections.Reflections.<init>(Reflections.java:168) [reflections-0.9.11.jar:na]
        at org.reflections.Reflections.<init>(Reflections.java:141) [reflections-0.9.11.jar:na]
        at com.shardis.query.schema.support.SchemaExporter.<init>(SchemaExporter.kt:27) [test/:na]
        at com.shardis.query.schema.SchemaExporterTest.generateDDL(SchemaExporterTest.kt:23) [test/:na]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_131]
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_131]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_131]
        at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_131]
        at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50) [junit-4.12.jar:4.12]
        at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) [junit-4.12.jar:4.12]
        at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47) [junit-4.12.jar:4.12]
        at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) [junit-4.12.jar:4.12]
        at org.springframework.test.context.junit4.statements.RunBeforeTestExecutionCallbacks.evaluate(RunBeforeTestExecutionCallbacks.java:73) [spring-test-5.0.0.RC2.jar:5.0.0.RC2]
        at org.springframework.test.context.junit4.statements.RunAfterTestExecutionCallbacks.evaluate(RunAfterTestExecutionCallbacks.java:83) [spring-test-5.0.0.RC2.jar:5.0.0.RC2]
        at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75) [spring-test-5.0.0.RC2.jar:5.0.0.RC2]
        at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86) [spring-test-5.0.0.RC2.jar:5.0.0.RC2]
        at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84) [spring-test-5.0.0.RC2.jar:5.0.0.RC2]
        at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325) [junit-4.12.jar:4.12]
        at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:250) [spring-test-5.0.0.RC2.jar:5.0.0.RC2]
        at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:97) [spring-test-5.0.0.RC2.jar:5.0.0.RC2]
        at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) [junit-4.12.jar:4.12]
        at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) [junit-4.12.jar:4.12]
        at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) [junit-4.12.jar:4.12]
        at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) [junit-4.12.jar:4.12]
        at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) [junit-4.12.jar:4.12]
        at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61) [spring-test-5.0.0.RC2.jar:5.0.0.RC2]
        at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70) [spring-test-5.0.0.RC2.jar:5.0.0.RC2]
        at org.junit.runners.ParentRunner.run(ParentRunner.java:363) [junit-4.12.jar:4.12]
        at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:189) [spring-test-5.0.0.RC2.jar:5.0.0.RC2]
        at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecuter.runTestClass(JUnitTestClassExecuter.java:114) [gradle-testing-jvm-4.0.jar:4.0]
        at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecuter.execute(JUnitTestClassExecuter.java:57) [gradle-testing-jvm-4.0.jar:4.0]
        at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassProcessor.processTestClass(JUnitTestClassProcessor.java:66) [gradle-testing-jvm-4.0.jar:4.0]
        at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.processTestClass(SuiteTestClassProcessor.java:51) [gradle-testing-base-4.0.jar:4.0]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_131]
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_131]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_131]
        at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_131]
        at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35) [gradle-messaging-4.0.jar:4.0]
        at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24) [gradle-messaging-4.0.jar:4.0]
        at org.gradle.internal.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:32) [gradle-messaging-4.0.jar:4.0]
        at org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:93) [gradle-messaging-4.0.jar:4.0]
        at com.sun.proxy.$Proxy1.processTestClass(Unknown Source) [na:na]
        at org.gradle.api.internal.tasks.testing.worker.TestWorker.processTestClass(TestWorker.java:109) [gradle-testing-base-4.0.jar:4.0]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_131]
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_131]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_131]
        at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_131]
        at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35) [gradle-messaging-4.0.jar:4.0]
        at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24) [gradle-messaging-4.0.jar:4.0]
        at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:146) [gradle-messaging-4.0.jar:4.0]
        at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:128) [gradle-messaging-4.0.jar:4.0]
        at org.gradle.internal.remote.internal.hub.MessageHub$Handler.run(MessageHub.java:404) [gradle-messaging-4.0.jar:4.0]
        at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63) [gradle-base-services-4.0.jar:4.0]
        at org.gradle.internal.concurrent.StoppableExecutorImpl$1.run(StoppableExecutorImpl.java:46) [gradle-base-services-4.0.jar:4.0]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_131]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_131]
        at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55) [gradle-base-services-4.0.jar:4.0]
        at java.lang.Thread.run(Thread.java:748) [na:1.8.0_131]

kucharzyk avatar Jun 19 '17 20:06 kucharzyk

yes , I am checking and trying solutions .Will update you.

avinashchavanfidel avatar Sep 08 '17 17:09 avinashchavanfidel

I'm getting the same problem. It looks like it has something to do with .useParallelExecutor(). I've used reflections once before with .useParallelExecutor(). Then I tried to use it again later on in my code, also with .useParallelExecutor() then I get the failure. Removing the .useParallelExecutor() fixes the problem.

jctetter avatar Sep 21 '17 19:09 jctetter

any update on this?

kopax avatar Nov 04 '17 19:11 kopax

Upgraded to macOS High Sierra, and now my gradle build is starting to show this as well.

This is pretty annoying. Anyways I/we can help out to fix this?

Cheers, Alf

stoyle avatar Nov 20 '17 09:11 stoyle

I'm getting this all the time when running a gradle build in docker. I presume the docker and overlay filesystem is the difference? Some different file type that isn't supported? 🤷‍♂️

nhoughto avatar Feb 04 '18 08:02 nhoughto

To quiet the logging add the following in src/main/resources/logback.xml

<logger name="org.reflections.Reflections" level="error"
	additivity="false">
	<appender-ref ref="STDOUT" />
</logger>

tcollinsworth avatar Feb 28 '18 17:02 tcollinsworth

I had this same problem. What solved it for me was changing my config from using ClasspathHelper.forClassLoader() to ClasspathHelper.forJavaClassPath(), so:

ConfigurationBuilder config = new ConfigurationBuilder()
        .setUrls( ClasspathHelper.forJavaClassPath() )
        .addScanners( TypesAnnotated );

DeegC avatar Nov 26 '21 03:11 DeegC

In my case I got this error because the collection of URLs contained a non-existent directory. Filtering it out solved the problem:

List<URL> urls =
      ClasspathHelper.forJavaClassPath()
            .stream()
            .filter(url -> new File(url.toString()).exists())
            .collect(Collectors.toList());
new Reflections(new ConfigurationBuilder().setUrls(urls));

J4NS-R avatar May 23 '24 10:05 J4NS-R