reflections icon indicating copy to clipboard operation
reflections copied to clipboard

Exception when trying to instantiate Reflections

Open Rafaelsk opened this issue 7 years ago • 5 comments

Under JDK8:

Code:

Reflections reflections = new Reflections("my.package");

Exception

java.lang.NoSuchMethodError: com.google.common.collect.Sets$SetView.iterator()Lcom/google/common/collect/UnmodifiableIterator;
	at org.reflections.Reflections.expandSuperTypes(Reflections.java:380) ~[reflections-0.9.11.jar:na]
	at org.reflections.Reflections.<init>(Reflections.java:126) ~[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]

Rafaelsk avatar Apr 24 '18 15:04 Rafaelsk

That means you have an old version of Guava in your class path. Check your Guava version.

isaki avatar Apr 24 '18 15:04 isaki

I see the project have 2 guava libraries version 18.0 and 20.0 respectively.

Rafaelsk avatar Apr 24 '18 16:04 Rafaelsk

20.0 is pulled in by Reflections most likely, but 18.0 is probably winning. You could try setting up managed dependencies to force only 20. I currently force 24.1-jre and it works well.

isaki avatar Apr 25 '18 16:04 isaki

@Rafaelsk I have also encountered this problem, how do you solve it?

haixuan8192 avatar May 24 '18 07:05 haixuan8192

@haixuan8192 I didn't. I couldn't use the library so I used Java's plain Reflection code form the JDK library.

Rafaelsk avatar May 28 '18 07:05 Rafaelsk