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

Be lenient with ServiceLoader not able to load classes #411

Merged
merged 1 commit into from
Nov 19, 2024
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
19 changes: 15 additions & 4 deletions sdk-core/src/main/java/dev/restate/sdk/core/RestateEndpoint.java
Original file line number Diff line number Diff line change
Expand Up @@ -223,10 +223,21 @@ private static class ServiceDefinitionFactoryDiscovery {
private final List<ServiceDefinitionFactory> factories;

private ServiceDefinitionFactoryDiscovery() {
this.factories =
ServiceLoader.load(ServiceDefinitionFactory.class).stream()
.map(ServiceLoader.Provider::get)
.collect(Collectors.toList());
this.factories = new ArrayList<>();

var serviceLoaderIterator = ServiceLoader.load(ServiceDefinitionFactory.class).iterator();
while (serviceLoaderIterator.hasNext()) {
try {
this.factories.add(serviceLoaderIterator.next());
} catch (ServiceConfigurationError | Exception e) {
LOG.debug(
"Found service that cannot be loaded using service provider. "
+ "You can ignore this message during development.\n"
+ "This might be the result of using a compiler with incremental builds (e.g. IntelliJ IDEA) "
+ "that updated a dirty META-INF file after removing/renaming an annotated service.",
e);
}
}
}

private @Nullable ServiceDefinitionFactory discoverFactory(Object service) {
Expand Down
Loading