{"record":{"id":"e7bc49bbe6e37116","repo":"pentaho/pentaho-kettle","slug":"defaultauthenticationconsumerfactory-constructor-arg","errorCode":"DefaultAuthenticationConsumerFactory.Constructor.Arg","errorMessage":"DefaultAuthenticationConsumerFactory.Constructor.Arg","messagePattern":"DefaultAuthenticationConsumerFactory\\.Constructor\\.Arg","errorType":"error_code","errorClass":"AuthenticationFactoryException","httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/core/auth/core/impl/DefaultAuthenticationConsumerFactory.java","lineNumber":44,"sourceCode":"  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] ) ) {\n          consumeMethod = method;\n          consumedType = methodParameterTypes[0];\n        }\n      }\n    }\n\n    if ( consumeMethod == null ) {\n      throw new AuthenticationFactoryException( BaseMessages.getString( PKG,","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/core/auth/core/impl/DefaultAuthenticationConsumerFactory.java#L26-L62","documentation":"After picking the single public constructor, DefaultAuthenticationConsumerFactory requires it to take exactly one parameter; a zero-arg or multi-arg constructor triggers AuthenticationFactoryException with key 'DefaultAuthenticationConsumerFactory.Constructor.Arg'. The framework creates consumers by passing one argument (the authentication provider).","triggerScenarios":"Registering a consumer class whose single public constructor has parameterTypes.length != 1 (e.g. a no-arg constructor or one taking two dependencies).","commonSituations":"DI-style consumers with several injected dependencies; default constructors on consumers written for standalone use; Lombok @AllArgsConstructor over multiple fields.","solutions":["Change the consumer to a single-argument public constructor accepting the provider/consumed dependency.","Bundle extra dependencies into one parameter object, or inject them another way before consume() runs.","Use a custom AuthenticationConsumerFactory instead of the default if the constructor contract cannot be met."],"exampleFix":"// before\npublic MyConsumer(AuthenticationProvider p, Log log) {}\n// after\npublic MyConsumer(AuthenticationProvider p) { this.log = Log.getInstance(); }","handlingStrategy":"validation","validationCode":"Constructor<?> c = MyConsumer.class.getConstructors()[0];\nif (c.getParameterTypes().length != 1) {\n  throw new IllegalStateException(\"Consumer constructor must take exactly one argument\");\n}","typeGuard":null,"tryCatchPattern":"try { new DefaultAuthenticationConsumerFactory(MyConsumer.class); } catch (AuthenticationFactoryException e) { logError(\"Consumer must take one constructor arg\", e); }","preventionTips":["Design consumers with a single-argument constructor","Move auxiliary dependencies out of the constructor","Write a unit test that instantiates the factory for every consumer"],"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"}