apache/beam · error · RuntimeException

Could not find a matching constructor method. When using…

Error message

Could not find a matching constructor method. When using field names, make sure they are available in the compiled Java class.

What it means

findMappingConstructorMethod filters the class's methods by constructor-method allowlist/annotation, parameter count, and parameter compatibility with the Row. If no method survives the filters, it throws RuntimeException advising that field names must be available in the compiled class.

Solutions

  1. Verify payload.getConstructorMethod() matches an existing public method name in the target class.
  2. Recompile with -parameters so name-based matching works.
  3. Ensure the method name is in the allowlist (see permission errors) so it is not filtered out.
  4. Check the schema field count and types against the method signature; adjust the payload schema.

Example fix

// before: payload references removed method
"constructorMethod": "fromConfig"  // method deleted
// after
"constructorMethod": "create"      // matches existing @MultiLanguageConstructorMethod(name="create")
Defensive patterns

Strategy: try-catch

Validate before calling

Method m = Arrays.stream(Target.class.getMethods()).filter(x -> x.getName().equals(payload.getConstructorMethod())).findFirst().orElseThrow(() -> new IllegalStateException("Method not found: " + payload.getConstructorMethod())); if (m.getParameterCount() != schema.getFieldsCount()) throw new IllegalStateException("Arity mismatch");

Try / catch

try { method(payload); } catch (RuntimeException e) { if (e.getMessage().contains("Could not find a matching constructor method")) { /* verify method name, allowlist, arity */ } throw e; }

Prevention

When it happens

Trigger: method(payload) invoked where payload.getConstructorMethod() names a method that does not exist, is not an allowed constructor method (filtered out by isConstructorMethodForName), has a different arity than the schema fields, or has incompatible parameter types.

Common situations: Method renamed or removed while payloads still reference it; compilation without -parameters breaking name matching; wrong constructorMethod string in the cross-language payload.

Related errors


AI-assisted analysis of apache/beam@12126d8942 (2026-09-13). Data as JSON: /api/errors/8e521672459ed510. Report an issue: GitHub.

Appendix: source

Thrown at sdks/java/expansion-service/src/main/java/org/apache/beam/sdk/expansion/service/JavaClassLookupTransformProvider.java:465

    }
    return false;
  }

  private Method findMappingConstructorMethod(
      Method[] methods, JavaClassLookupPayload payload, AllowedClass allowListClass) {

    Row constructorRow = decodeRow(payload.getConstructorSchema(), payload.getConstructorPayload());

    List<Method> mappingConstructorMethods =
        Arrays.stream(methods)
            .filter(
                m -> isConstructorMethodForName(m, payload.getConstructorMethod(), allowListClass))
            .filter(m -> m.getParameterCount() == payload.getConstructorSchema().getFieldsCount())
            .filter(m -> parametersCompatible(m.getParameters(), constructorRow))
            .collect(Collectors.toList());

    if (mappingConstructorMethods.size() == 0) {
      throw new RuntimeException(
          "Could not find a matching constructor method. When using field names, make sure they "
              + "are available in the compiled Java class.");
    } else if (mappingConstructorMethods.size() != 1) {
      throw new RuntimeException(
          "Expected to find a single mapping constructor method but found "
              + mappingConstructorMethods.size()
              + " Payload was "
              + payload);
    }
    return mappingConstructorMethods.get(0);
  }

  @AutoValue
  public abstract static class AllowList {

    public static AllowList nothing() {
      return create(ALLOW_LIST_VERSION, Collections.emptyList());
    }

View on GitHub (pinned to 12126d8942)