prestodb/presto · error · RuntimeException
Error creating an instance of %s
Error message
Error creating an instance of %s
What it means
PrestoS3ClientFactory.getCustomAWSCredentialsProvider instantiates a user-configured AWSCredentialsProvider class reflectively (constructor taking (URI, Configuration)) via conf.getClassByName(...).getConstructor(...).newInstance(...). Any ReflectiveOperationException (class missing, no matching constructor, constructor threw) is rethrown as RuntimeException 'Error creating an instance of %s'.
Source
Thrown at presto-hive/src/main/java/com/facebook/presto/hive/s3/PrestoS3ClientFactory.java:163
String providerClass = conf.get(S3_CREDENTIALS_PROVIDER);
if (!isNullOrEmpty(providerClass)) {
return getCustomAWSCredentialsProvider(conf, providerClass);
}
return DefaultAWSCredentialsProviderChain.getInstance();
}
private static AWSCredentialsProvider getCustomAWSCredentialsProvider(Configuration conf, String providerClass)
{
try {
return conf.getClassByName(providerClass)
.asSubclass(AWSCredentialsProvider.class)
.getConstructor(URI.class, Configuration.class)
.newInstance(null, conf);
}
catch (ReflectiveOperationException e) {
throw new RuntimeException(format("Error creating an instance of %s", providerClass), e);
}
}
private static Optional<AWSCredentials> getAwsCredentials(Configuration conf)
{
String accessKey = conf.get(S3_ACCESS_KEY);
String secretKey = conf.get(S3_SECRET_KEY);
if (isNullOrEmpty(accessKey) || isNullOrEmpty(secretKey)) {
return Optional.empty();
}
return Optional.of(new BasicAWSCredentials(accessKey, secretKey));
}
}
View on GitHub (pinned to 55bb57d202)
Solutions
- Check the wrapped cause in the message: ClassNotFoundException -> deploy the jar; NoSuchMethodException -> add a (URI, Configuration) constructor; InvocationTargetException -> fix the provider's constructor.
- Implement the provider as public class X implements AWSCredentialsProvider with a public constructor (URI, Configuration).
- Deploy the provider jar to the hive plugin directory (presto-hive/target or plugin/hive-hadoop2/...) on EVERY node and restart.
- Verify the class name matches hive.s3.credentials-provider exactly (package + class, case-sensitive).
Example fix
// before: no (URI, Configuration) constructor
public class MyProvider implements AWSCredentialsProvider {
public MyProvider() { ... }
}
// after
public class MyProvider implements AWSCredentialsProvider {
public MyProvider(URI uri, Configuration conf) { ... }
@Override public AWSCredentials getCredentials() { ... }
@Override public void refresh() { ... }
} Defensive patterns
Strategy: validation
Validate before calling
// pre-check the configured credentials provider before wiring it into the catalog
Class<?> cls = Class.forName(conf.get("hive.s3.credentials-provider"));
if (!AWSCredentialsProvider.class.isAssignableFrom(cls)) throw new IllegalStateException("Not an AWSCredentialsProvider");
cls.getConstructor(URI.class, Configuration.class); // throws NoSuchMethodException if signature missing Type guard
boolean isValidCredentialsProvider(String className, ClassLoader cl) {
try {
Class<?> c = Class.forName(className, false, cl);
return AWSCredentialsProvider.class.isAssignableFrom(c)
&& c.getConstructor(URI.class, Configuration.class) != null;
} catch (ReflectiveOperationException e) { return false; }
} Try / catch
try {
AWSCredentialsProvider p = buildProvider(providerClass, uri, conf);
} catch (RuntimeException e) {
if (e.getMessage() != null && e.getMessage().startsWith("Error creating an instance of ")) {
Throwable cause = e.getCause();
// ClassNotFoundException: deploy jar; NoSuchMethodException: fix constructor; InvocationTargetException: fix ctor internals
throw new ProviderInitException("Fix provider " + providerClass + " (cause: " + cause + ")");
}
throw e;
} Prevention
- Implement providers with the exact public (URI, Configuration) constructor.
- Deploy the provider jar to plugin/hive-hadoop2/ on every node and restart after upgrades.
- Keep the provider compiled against the AWS SDK version bundled with Presto.
- Smoke-test the provider in a unit test before wiring it into production config.
When it happens
Trigger: hive.s3.credentials-provider is set to a class that: doesn't exist on the classpath (ClassNotFoundException), lacks a (URI, Configuration) constructor (NoSuchMethodException), isn't an AWSCredentialsProvider subclass, or whose constructor throws (InvocationTargetException) — e.g., reading a missing credentials file in its constructor.
Common situations: Typo in the fully-qualified class name; custom provider jar not deployed to the hive plugin directory on all nodes; provider written against a different SDK version where the constructor signature changed; provider fails at runtime because it depends on env vars/files absent on workers.
Related errors
- Invalid encryption materials provider class:
- Unable to load or create S3 encryption materials provider: $
- Error creating an instance of %s for URI %s
- Unknown file system type:
- EMR File System class not found:
AI-assisted analysis of prestodb/presto@55bb57d202 (2026-09-04).
Data as JSON: /api/errors/35779e46ff526f69.
Report an issue: GitHub.