Skip to content

Commit

Permalink
Be lenient with ServiceLoader not able to load classes. This makes th…
Browse files Browse the repository at this point in the history
…e annotation processor experience better on incremental compilers (#411)
  • Loading branch information
slinkydeveloper authored Nov 19, 2024
1 parent f94aeec commit 85292d4
Showing 1 changed file with 15 additions and 4 deletions.
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

0 comments on commit 85292d4

Please sign in to comment.