apache/beam · error · RuntimeException
Impossible state: missing 'apply' method entirely
Error message
Impossible state: missing 'apply' method entirely
What it means
InferableFunction's no-arg constructor uses reflection to locate the subclass's 'apply' method (declared in the Function interface). If reflection returns NoSuchMethodException, the class cannot even see an apply method, which should be impossible for a well-formed subclass — hence 'impossible state'. This indicates a broken/obfuscated subclass or a reflection failure, and the library wraps it in a RuntimeException.
Solutions
- Ensure the subclass overrides public OutputT apply(InputT input), or pass a ProcessFunction (lambda/method reference) to the protected constructor: new InferableFunction<InputT,OutputT>(x -> ...)
- If using ProGuard/R8, add keep rules for the apply method and InferableFunction subclasses
- Verify the deployed jar's bytecode matches the source (no stale/obfuscated classes)
Example fix
// before
class MyFn<I, O> extends InferableFunction<I, O> { }
// after
class MyFn<I, O> extends InferableFunction<I, O> {
@Override
public O apply(I input) { return transform(input); }
} Defensive patterns
Strategy: type-guard
Validate before calling
boolean ok = false;
for (Method m : MyFn.class.getMethods()) {
if (m.getName().equals("apply") && !m.isSynthetic()) { ok = true; break; }
}
if (!ok) throw new IllegalStateException("MyFn must override apply"); Type guard
static boolean hasApplyMethod(Class<?> c) {
try { c.getMethod("apply", Object.class); return true; }
catch (NoSuchMethodException e) { return false; }
} Try / catch
try {
InferableFunction<I, O> fn = new MyFn<>();
} catch (RuntimeException e) {
if (e.getMessage() != null && e.getMessage().contains("Impossible state")) {
// fall back to explicit ProcessFunction
fn = new InferableFunction<>(input -> transform(input));
} else { throw e; }
} Prevention
- Always override apply() in InferableFunction subclasses
- Prefer passing a lambda/ProcessFunction to the constructor instead of subclassing
- Add ProGuard/R8 keep rules for apply methods in production builds
When it happens
Trigger: Instantiating a subclass of InferableFunction via the public no-arg constructor when getMethod("apply") throws NoSuchMethodException — e.g. the subclass does not actually override/declare apply, or bytecode processing/proguard removed or renamed it.
Common situations: Custom DoFn mapping functions written as anonymous classes missing the apply override; ProGuard/R8 stripping method names in production builds; class-loading quirks in shaded jars.
Understand the failure class
Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.
Related errors
- AutoValue builder class
- Can not call prepareRun
- cannot register Coder : does not have an accessible method…
- cannot register Coder : method named 'of' with arguments…
- cannot register Coder : method named 'of' with arguments…
AI-assisted analysis of apache/beam@12126d8942 (2026-09-13).
Data as JSON: /api/errors/7c245789daf122cc.
Report an issue: GitHub.
Appendix: source
Thrown at sdks/java/core/src/main/java/org/apache/beam/sdk/transforms/InferableFunction.java:59
protected InferableFunction() {
this.fn = null;
// A subclass must override apply if using this constructor. Check that via
// reflection.
try {
Method methodThatMustBeOverridden =
InferableFunction.class.getDeclaredMethod("apply", Object.class);
Method methodOnSubclass = getClass().getMethod("apply", Object.class);
if (methodOnSubclass.equals(methodThatMustBeOverridden)) {
throw new IllegalStateException(
"Subclass of InferableFunction must override 'apply' method"
+ " or pass a ProcessFunction to the constructor,"
+ " usually via a lambda or method reference.");
}
} catch (NoSuchMethodException exc) {
throw new RuntimeException("Impossible state: missing 'apply' method entirely", exc);
}
}
protected InferableFunction(ProcessFunction<InputT, OutputT> fn) {
this.fn = fn;
}
@Override
public OutputT apply(InputT input) throws Exception {
return fn.apply(input);
}
public static <InputT, OutputT>
InferableFunction<InputT, OutputT> fromProcessFunctionWithOutputType(
ProcessFunction<InputT, OutputT> fn, TypeDescriptor<OutputT> outputType) {
return new InferableFunctionWithOutputType<>(fn, outputType);
}
View on GitHub (pinned to 12126d8942)