Skip to content

Commit

Permalink
Do not use singleton ServiceLoader
Browse files Browse the repository at this point in the history
  • Loading branch information
Amar3tto committed Feb 13, 2025
1 parent fc43c12 commit 4979d65
Showing 1 changed file with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,6 @@
"rawtypes"
})
public class ConvertHelpers {
private static class SchemaInformationProviders {
private static final ServiceLoader<SchemaInformationProvider> INSTANCE =
ServiceLoader.load(SchemaInformationProvider.class);
}

private static final Logger LOG = LoggerFactory.getLogger(ConvertHelpers.class);

Expand All @@ -87,11 +83,15 @@ public static <T> ConvertedSchemaInformation<T> getConvertedSchemaInformation(

ConvertedSchemaInformation<T> schemaInformation = null;
// Try to load schema information from loaded providers
for (SchemaInformationProvider provider : SchemaInformationProviders.INSTANCE) {
schemaInformation = provider.getConvertedSchemaInformation(inputSchema, outputType);
if (schemaInformation != null) {
return schemaInformation;
try {
for (SchemaInformationProvider provider : ServiceLoader.load(SchemaInformationProvider.class)) {
schemaInformation = provider.getConvertedSchemaInformation(inputSchema, outputType);
if (schemaInformation != null) {
return schemaInformation;
}
}
} catch (Exception e) {
LOG.debug("No Schema information found for type {}", outputType, e);
}

if (schemaInformation == null) {
Expand All @@ -107,7 +107,7 @@ public static <T> ConvertedSchemaInformation<T> getConvertedSchemaInformation(
schemaRegistry.getToRowFunction(outputType),
schemaRegistry.getFromRowFunction(outputType));
} catch (NoSuchSchemaException e) {
LOG.debug("No schema found for type " + outputType, e);
LOG.debug("No schema found for type {}", outputType, e);
}
FieldType unboxedType = null;
// TODO: Properly handle nullable.
Expand Down

0 comments on commit 4979d65

Please sign in to comment.