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

Provide insightful information for classloader issues #24973

Merged
merged 1 commit into from
Feb 10, 2025
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,15 @@ protected Class<?> loadClass(String name, boolean resolve)

// If this is an SPI class, only check SPI class loader
if (isSpiClass(name)) {
return resolveClass(spiClassLoader.loadClass(name), resolve);
try {
return resolveClass(spiClassLoader.loadClass(name), resolve);
}
catch (ClassNotFoundException e) {
if (hasClassLocally(name, resolve)) {
throw new ClassNotFoundException("SPI class '%s' was not found in the SPI classloader, but was found in the '%s' plugin classloader. Dependency providing this class should be added to the trino-spi provided scope.".formatted(name, pluginName), e);
}
throw new ClassNotFoundException("SPI class '%s' was not found in the SPI classloader. This is probably a bug in the dependencies.".formatted(name), e);
}
}

// Look for class locally
Expand All @@ -115,6 +123,17 @@ private Class<?> resolveClass(Class<?> clazz, boolean resolve)
return clazz;
}

private boolean hasClassLocally(String name, boolean resolve)
{
try {
super.loadClass(name, resolve);
Copy link
Member

Choose a reason for hiding this comment

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

This is potentially problematic. This will have the side effects that the class may get loaded, the caller will throw an exception that may be caught by someone else, and things may start behaving in unexpected ways.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was already problematic if the class belong to an SPI_PACKAGES but couldn't be loaded through the SPI class loader. I've faced this issue recently.

return true;
}
catch (Exception e) {
return false;
}
}

@Override
public URL getResource(String name)
{
Expand Down
Loading