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

Fix ConfigurationBuilder addClassLoaders #288

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/main/java/org/reflections/util/ConfigurationBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
22 changes: 22 additions & 0 deletions src/test/java/org/reflections/util/ConfigurationBuilderTest.java
Original file line number Diff line number Diff line change
@@ -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 );
}
}