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

Services now checks the contextClassLoader, Services.class.classLoader, and the system classloader #574

Merged
merged 1 commit into from
Mar 12, 2020

Conversation

bdemers
Copy link
Member

@bdemers bdemers commented Mar 11, 2020

Services are now loaded from the context class loader, Services.class.classLoader, and the system classloader, the first classloader with a service wins, and the others are ignored. This mimics how Classes.forName() works, and how JJWT attempted to auto-discover various implementations in previous versions.

Fixes: #568

@bdemers bdemers requested a review from lhazlewood March 11, 2020 18:49
/**
* Helper class for loading services from the classpath, using a {@link ServiceLoader}. Decouples loading logic for
* better separation of concerns and testability.
*/
public final class Services {

private static final List<ClassLoaderAccessor> CLASS_LOADER_ACCESSORS = arrayToList(new ClassLoaderAccessor[] {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this class would be much cleaner and reduce cyclomatic complexity / loops if we wrapped the list in our own delegating ClassLoader implementation. Thoughts?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was going to go down that path, but I figured this option was less complex. Mostly because I'm unaware of any gotchas (ClassLoader is a 3000+ abstract class). I'm guessing the SecurityManager could come into play 🤷‍♂

@lhazlewood
Copy link
Contributor

It probably goes without saying, but I'll ask anyway - were you able to verify this works w/ @timsazon's sample app?

@lhazlewood
Copy link
Contributor

(didn't see your comment in the Issue until just now :-P )

Copy link
Contributor

@lhazlewood lhazlewood left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please merge! Thanks!

@bdemers bdemers merged commit 9e65ab7 into master Mar 12, 2020
@bdemers bdemers deleted the issue-568 branch March 12, 2020 19:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ServiceLocator can't find an implementation in common-pool workers
2 participants