{"record":{"id":"68d2feb5c13ada75","repo":"apache/iceberg","slug":"cannot-create-an-instance-of-s-it-does-not-conta-68d2fe","errorCode":null,"errorMessage":"Cannot create an instance of %s, it does not contain a static 'create' or 'create(Map<String, String>)' method","messagePattern":"Cannot create an instance of (.+?), it does not contain a static 'create' or 'create\\(Map<String, String>\\)' method","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"aws/src/main/java/org/apache/iceberg/aws/AwsProperties.java","lineNumber":594,"sourceCode":"            \"Cannot initialize %s, it does not implement %s.\",\n            credentialsProviderClass, AwsCredentialsProvider.class.getName()));\n\n    AwsCredentialsProvider provider;\n    try {\n      try {\n        provider =\n            DynMethods.builder(\"create\")\n                .hiddenImpl(providerClass, Map.class)\n                .buildStaticChecked()\n                .invoke(clientCredentialsProviderProperties);\n      } catch (NoSuchMethodException e) {\n        provider =\n            DynMethods.builder(\"create\").hiddenImpl(providerClass).buildStaticChecked().invoke();\n      }\n\n      return provider;\n    } catch (NoSuchMethodException e) {\n      throw new IllegalArgumentException(\n          String.format(\n              \"Cannot create an instance of %s, it does not contain a static 'create' or 'create(Map<String, String>)' method\",\n              credentialsProviderClass),\n          e);\n    }\n  }\n\n  private <T extends SdkClientBuilder> void configureEndpoint(T builder, String endpoint) {\n    if (endpoint != null) {\n      builder.endpointOverride(URI.create(endpoint));\n    }\n  }\n}\n","sourceCodeStart":576,"sourceCodeEnd":608,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/aws/src/main/java/org/apache/iceberg/aws/AwsProperties.java#L576-L608","documentation":"AwsProperties.credentialsProvider instantiates the loaded provider class reflectively, first trying create(Map) then create(); if neither static factory method exists, NoSuchMethodException is wrapped as this IllegalArgumentException. Iceberg requires this convention so providers can optionally receive the configuration map.","triggerScenarios":"The class configured as the credentials provider exists but defines no static create() or create(Map<String, String>) method — instantiation via DynMethods fails and this error is thrown from AwsProperties.credentialsProvider.","commonSituations":"Custom provider classes with only constructors; SDK-built-in providers lacking Iceberg-style create factories; accidentally deleting or renaming the create method during refactoring.","solutions":["Implement public static create() or public static create(Map<String, String>) in the provider class.","If configuration is needed, prefer create(Map<String, String>) and read properties from the map.","Alternatively wrap the class in an adapter that exposes the required static factory."],"exampleFix":"// before\nclass StaticProvider implements AwsCredentialsProvider {\n  StaticProvider() {}\n}\n// after\nclass StaticProvider implements AwsCredentialsProvider {\n  public static AwsCredentialsProvider create(Map<String, String> properties) { return new StaticProvider(); }\n}","handlingStrategy":"type-guard","validationCode":"Class<?> c = Class.forName(providerClassName);\nboolean hasFactory = java.util.Arrays.stream(c.getMethods()).anyMatch(m ->\n    m.getName().equals(\"create\") && java.lang.reflect.Modifier.isStatic(m.getModifiers()));\nif (!hasFactory) throw new IllegalStateException(providerClassName + \" lacks static create factory\");","typeGuard":"static boolean hasCreateMethod(Class<?> c) {\n  return java.util.Arrays.stream(c.getDeclaredMethods()).anyMatch(m ->\n      m.getName().equals(\"create\") && java.lang.reflect.Modifier.isStatic(m.getModifiers()));\n}","tryCatchPattern":"try {\n  s3 = new S3FileIO(config);\n} catch (IllegalArgumentException e) {\n  if (e.getMessage().contains(\"'create' or 'create(Map\")) {\n    LOG.error(\"Provider {} needs a static create method\", config.get(\"client.credentials-provider\"));\n  }\n  throw e;\n}","preventionTips":["Document and enforce the create()/create(Map) convention for all custom providers in your team's template.","Add a CI check that reflectively instantiates every configured provider class.","Use create(Map<String, String>) when properties are needed."],"tags":["aws","reflection","factory-method","invalid-constructor-argument"],"backgroundTag":"invalid-constructor-argument","analyzedSha":"86d9c8fc543e7c56c9f624eb725f76c9baff9570","analyzedAt":"2026-09-12T00:46:39.097Z","contentChangedAt":"2026-09-12T00:46:39.097Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}