diff --git a/src/main/java/org/reflections/util/ConfigurationBuilder.java b/src/main/java/org/reflections/util/ConfigurationBuilder.java index b61a28b3..22346380 100644 --- a/src/main/java/org/reflections/util/ConfigurationBuilder.java +++ b/src/main/java/org/reflections/util/ConfigurationBuilder.java @@ -301,9 +301,9 @@ public ConfigurationBuilder addClassLoader(ClassLoader classLoader) { /** add class loader, might be used for resolving methods/fields */ public ConfigurationBuilder addClassLoaders(ClassLoader... classLoaders) { - this.classLoaders = this.classLoaders == null ? classLoaders : - Stream.concat(Stream.concat(Arrays.stream(this.classLoaders), Arrays.stream(classLoaders)), Stream.of(ClassLoader.class)) - .distinct().toArray(ClassLoader[]::new); + this.classLoaders = this.classLoaders == null + ? classLoaders + : Stream.concat(Arrays.stream(this.classLoaders), Arrays.stream(classLoaders)).toArray(ClassLoader[]::new); return this; } diff --git a/src/test/java/org/reflections/util/ConfigurationBuilderTest.java b/src/test/java/org/reflections/util/ConfigurationBuilderTest.java new file mode 100644 index 00000000..46a169ad --- /dev/null +++ b/src/test/java/org/reflections/util/ConfigurationBuilderTest.java @@ -0,0 +1,22 @@ +package org.reflections.util; + +import org.junit.Test; + +import static org.junit.Assert.*; + +public class ConfigurationBuilderTest +{ + @Test + public void testCallingAddClassLoaderMoreThanOnce() + { + ClassLoader fooClassLoader = new ClassLoader() { }; + ClassLoader barClassLoader = new ClassLoader() { }; + + ConfigurationBuilder configurationBuilder = new ConfigurationBuilder() + .addClassLoader( fooClassLoader ); + + // Attempt to add a second class loader + configurationBuilder.addClassLoader( barClassLoader ); + assertTrue( true ); + } +} \ No newline at end of file