apache/druid · error · ProvisionException

JsonConfigurator requires default classes to have zero-arg c

Error message

JsonConfigurator requires default classes to have zero-arg constructors. %s doesn't

What it means

When binding a config via JsonConfigurator.configurate, the optional 'default' instance class must be constructible by Druid: it must either have a Jackson @JsonCreator factory method or a public zero-arg constructor. verifyClazzIsConfigurable throws this ProvisionException when the configured default class has neither, so the injector cannot instantiate a default config bean.

Source

Thrown at processing/src/main/java/org/apache/druid/guice/JsonConfigurator.java:275

    hieraricalPutValue(propertyPrefix, originalProperty, property.substring(dotIndex + 1), value, nestedMap);
  }

  @VisibleForTesting
  @SuppressWarnings("ReturnValueIgnored")
  public static <T> void verifyClazzIsConfigurable(
      ObjectMapper mapper,
      Class<T> clazz,
      @Nullable Class<? extends T> defaultClass
  )
  {
    if (defaultClass != null) {
      try {
        if (findJsonCreatorFactoryMethod(defaultClass).isEmpty()) {
          defaultClass.getConstructor();
        }
      }
      catch (NoSuchMethodException e) {
        throw new ProvisionException(
            StringUtils.format(
                "JsonConfigurator requires default classes to have zero-arg constructors. %s doesn't",
                defaultClass
            )
        );
      }
    }

    final List<BeanPropertyDefinition> beanDefs = mapper.getSerializationConfig()
                                                        .introspect(mapper.constructType(clazz))
                                                        .findProperties();
    for (BeanPropertyDefinition beanDef : beanDefs) {
      final AnnotatedField field = beanDef.getField();
      if (field == null || !field.hasAnnotation(JsonProperty.class)) {
        throw new ProvisionException(
            StringUtils.format(
                "JsonConfigurator requires Jackson-annotated Config objects to have field annotations. %s doesn't",
                clazz

View on GitHub (pinned to 9b90983fd2)

Solutions

  1. Add a public no-arg constructor to the default class
  2. Or add a @JsonCreator-annotated static factory/constructor method for Jackson deserialization
  3. If the class is third-party and unmodifiable, wrap it in your own class with a zero-arg constructor and bind that

Example fix

// before
public class MyConfig {
  public MyConfig(int x) { ... }
}
// after
public class MyConfig {
  @JsonCreator
  public MyConfig(@JsonProperty("x") int x) { ... }
  // or: public MyConfig() { ... }
}
Defensive patterns

Strategy: validation

Validate before calling

static void assertConfigurable(Class<?> clazz) throws NoSuchMethodException {
  if (JsonConfigurator.findJsonCreatorFactoryMethod(clazz).isEmpty()) clazz.getConstructor();
}

Type guard

boolean isConfigurableDefault(Class<?> c) {
  return !JsonConfigurator.findJsonCreatorFactoryMethod(c).isEmpty()
      || java.util.Arrays.stream(c.getConstructors()).anyMatch(ctor -> ctor.getParameterCount() == 0);
}

Try / catch

try { binder.bind(...); } catch (ProvisionException e) { if (e.getMessage().contains("zero-arg constructors")) log.error("Add no-arg ctor or @JsonCreator to {}", e.getMessage()); throw e; }

Prevention

When it happens

Trigger: configurate() calls verifyClazzIsConfigurable on the default class supplied to the binder; findJsonCreatorFactoryMethod returns empty and getConstructor() throws NoSuchMethodException.

Common situations: Binding a custom config class (or third-party class) with only constructor arguments and no default constructor and no @JsonCreator; missing @JsonCreator on a static factory; class written for a different serialization framework.

Related errors


AI-assisted analysis of apache/druid@9b90983fd2 (2026-09-07). Data as JSON: /api/errors/94a0dbf68d318f1a. Report an issue: GitHub.