Skip to content

·[DE-793] tolerate SPI ServiceConfigurationError #552

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

Merged
merged 1 commit into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
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
15 changes: 10 additions & 5 deletions core/src/main/java/com/arangodb/ArangoDB.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@

import javax.annotation.concurrent.ThreadSafe;
import javax.net.ssl.SSLContext;
import java.util.ArrayList;
import java.util.Collection;
import java.util.ServiceLoader;
import java.util.*;
import java.util.concurrent.Executor;

/**
Expand Down Expand Up @@ -618,7 +616,6 @@ public Builder serde(final ArangoSerde serde) {
*
* @param executor async downstream executor
* @return {@link ArangoDB.Builder}
*
* @deprecated for removal. To consume the responses in a custom executor use async CompletableFuture methods.
*/
@Deprecated
Expand All @@ -630,7 +627,15 @@ public Builder asyncExecutor(final Executor executor) {
@UnstableApi
protected ProtocolProvider protocolProvider(Protocol protocol) {
ServiceLoader<ProtocolProvider> loader = ServiceLoader.load(ProtocolProvider.class);
for (ProtocolProvider p : loader) {
Iterator<ProtocolProvider> iterator = loader.iterator();
while (iterator.hasNext()) {
ProtocolProvider p;
try {
p = iterator.next();
} catch (ServiceConfigurationError e) {
LOG.warn("ServiceLoader failed to load ProtocolProvider", e);
continue;
}
if (p.supportsProtocol(protocol)) {
return p;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,15 @@ public class ArangoConfig {
private static ArangoSerdeProvider serdeProvider(ContentType contentType) {
ServiceLoader<ArangoSerdeProvider> loader = ServiceLoader.load(ArangoSerdeProvider.class);
ArangoSerdeProvider serdeProvider = null;
for (ArangoSerdeProvider p : loader) {
Iterator<ArangoSerdeProvider> iterator = loader.iterator();
while (iterator.hasNext()) {
ArangoSerdeProvider p;
try {
p = iterator.next();
} catch (ServiceConfigurationError e) {
LOG.warn("ServiceLoader failed to load ArangoSerdeProvider", e);
continue;
}
if (contentType.equals(p.getContentType())) {
if (serdeProvider != null) {
throw new ArangoDBException("Found multiple serde providers! Please set explicitly the one to use.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Iterator;
import java.util.ServiceConfigurationError;
import java.util.ServiceLoader;

class InternalMapperProvider {
Expand All @@ -23,7 +25,15 @@ static ObjectMapper of(final ContentType contentType) {
}

ServiceLoader<JsonFactory> sl = ServiceLoader.load(JsonFactory.class);
for (JsonFactory jf : sl) {
Iterator<JsonFactory> iterator = sl.iterator();
while (iterator.hasNext()) {
JsonFactory jf;
try {
jf = iterator.next();
} catch (ServiceConfigurationError e) {
LOG.warn("ServiceLoader failed to load JsonFactory", e);
continue;
}
if (formatName.equals(jf.getFormatName())) {
if (contentType == ContentType.JSON) {
JacksonUtils.tryConfigureJsonFactory(jf);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Iterator;
import java.util.ServiceConfigurationError;
import java.util.ServiceLoader;

/**
Expand All @@ -27,7 +29,15 @@ public static ObjectMapper of(final ContentType contentType) {
}

ServiceLoader<JsonFactory> sl = ServiceLoader.load(JsonFactory.class);
for (JsonFactory jf : sl) {
Iterator<JsonFactory> iterator = sl.iterator();
while (iterator.hasNext()) {
JsonFactory jf;
try {
jf = iterator.next();
} catch (ServiceConfigurationError e) {
LOG.warn("ServiceLoader failed to load JsonFactory", e);
continue;
}
if (formatName.equals(jf.getFormatName())) {
if (contentType == ContentType.JSON) {
JacksonUtils.tryConfigureJsonFactory(jf);
Expand Down
Loading