Skip to content

Allow TransportBuilder.getTransportProvider() to specify custom class loader #210

Closed
@cthbleachbit

Description

I am integrating this library into a Minecraft Bukkit plugin and it seems like TransportBuilder is unable to find any transport providers despite the fact that two of them are listed in the service definitions inside the jar.

After some investigation, it looks like plugin class loader instance is needed for ServiceLoader to correctly find provider classes...

This works:

@Override
public void onEnable() {
	ServiceLoader<ITransportProvider> spiLoader = ServiceLoader.load(ITransportProvider.class, this.getClass().getClassLoader());
}

This doesn't:

@Override
public void onEnable() {
	ServiceLoader<ITransportProvider> spiLoader = ServiceLoader.load(ITransportProvider.class);
}

Currently field TransportBuilder#PROVIDERS is to be initialized with static life time. This leaves no way to properly initialize this field from a bukkit plugin even with reflection as attempting to reflect-assign this field causes lazy initialization and thus invoke getTransportProvider() (which will call ServiceLoader without a correct class loader).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions