{"record":{"id":"abf0682375fea04f","repo":"pentaho/pentaho-kettle","slug":"defaultauthenticationconsumerfactory-constructor","errorCode":null,"errorMessage":"DefaultAuthenticationConsumerFactory.Constructor","messagePattern":"DefaultAuthenticationConsumerFactory\\.Constructor","errorType":"exception","errorClass":"AuthenticationFactoryException","httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/core/auth/core/impl/DefaultAuthenticationConsumerFactory.java","lineNumber":36,"sourceCode":"import java.lang.reflect.Method;\n\nimport org.pentaho.di.core.auth.core.AuthenticationConsumer;\nimport org.pentaho.di.core.auth.core.AuthenticationConsumerFactory;\nimport org.pentaho.di.core.auth.core.AuthenticationFactoryException;\nimport org.pentaho.di.i18n.BaseMessages;\n\npublic class DefaultAuthenticationConsumerFactory implements AuthenticationConsumerFactory<Object, Object, Object> {\n  private static final Class<?> PKG = DefaultAuthenticationConsumerFactory.class;\n  private final Constructor<?> constructor;\n  private final Class<Object> consumedType;\n  private final Class<Object> returnType;\n  private final Class<Object> createArgType;\n\n  @SuppressWarnings( \"unchecked\" )\n  public DefaultAuthenticationConsumerFactory( Class<?> consumerClass ) throws AuthenticationFactoryException {\n    Constructor<?>[] constructors = consumerClass.getConstructors();\n    if ( constructors.length != 1 ) {\n      throw new AuthenticationFactoryException( BaseMessages.getString( PKG,\n          \"DefaultAuthenticationConsumerFactory.Constructor\", getClass().getName(),\n          consumerClass.getCanonicalName() ) );\n    }\n\n    constructor = constructors[0];\n    Class<?>[] parameterTypes = constructor.getParameterTypes();\n    if ( parameterTypes.length != 1 ) {\n      throw new AuthenticationFactoryException( BaseMessages.getString( PKG,\n          \"DefaultAuthenticationConsumerFactory.Constructor.Arg\", getClass().getName(), consumerClass\n              .getCanonicalName() ) );\n    }\n\n    Method consumeMethod = null;\n    Class<?> consumedType = Object.class;\n    for ( Method method : consumerClass.getMethods() ) {\n      if ( \"consume\".equals( method.getName() ) ) {\n        Class<?>[] methodParameterTypes = method.getParameterTypes();\n        if ( methodParameterTypes.length == 1 && consumedType.isAssignableFrom( methodParameterTypes[0] ) ) {","sourceCodeStart":18,"sourceCodeEnd":54,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/core/auth/core/impl/DefaultAuthenticationConsumerFactory.java#L18-L54","documentation":"DefaultAuthenticationConsumerFactory wraps a consumer class and requires it to expose exactly one public constructor; otherwise it throws AuthenticationFactoryException with message key 'DefaultAuthenticationConsumerFactory.Constructor'. The factory cannot unambiguously pick how to construct the consumer.","triggerScenarios":"new DefaultAuthenticationConsumerFactory(SomeConsumer.class) where consumerClass.getConstructors().length != 1 — the class has zero public constructors or more than one.","commonSituations":"Consumers with convenience/overloaded constructors; default-visibility constructor only (getConstructors() sees none); added a second constructor during refactoring.","solutions":["Give the consumer class exactly one public constructor (the one taking the single provider/create argument).","Reduce overloaded constructors or make extras private/package-private.","Pass a different consumer class that satisfies the single-public-constructor contract."],"exampleFix":"// before\npublic MyConsumer() {}\npublic MyConsumer(Provider p) {} // two public constructors\n// after\npublic MyConsumer(Provider p) {}\nprivate MyConsumer() {}","handlingStrategy":"validation","validationCode":"if (MyConsumer.class.getConstructors().length != 1) {\n  throw new IllegalStateException(\"Consumer must expose exactly one public constructor\");\n}","typeGuard":null,"tryCatchPattern":"try { new DefaultAuthenticationConsumerFactory(MyConsumer.class); } catch (AuthenticationFactoryException e) { logError(\"Constructor contract violated\", e); }","preventionTips":["Keep exactly one public constructor on consumer classes","Avoid Lombok constructors that generate multiple overloads","Review the single-constructor contract before refactoring consumers"],"tags":["authentication","constructor","reflection"],"backgroundTag":"invalid-constructor-argument","analyzedSha":"f3058517a153da500bf4551f46d79b91bf8ec552","analyzedAt":"2026-09-13T14:04:16.340Z","contentChangedAt":"2026-09-13T14:04:16.340Z","schemaVersion":2},"datasetVersion":"2026-09-20T23:17:15.980Z"}