apache/beam · error · RuntimeException

Unable to locate declared method.

Error message

Unable to locate declared method.

What it means

When StringCompiler's internal compile of a probe fails, guessExpressionType inspects the compiler diagnostics and, for type-mismatch diagnostics, tries to find a synthetic method named 'method' on the compiled class to infer the expression's type. If that method cannot be found among the class's methods — which the code comments should never happen — it throws this RuntimeException as an internal invariant failure. Any other original error is rethrown.

Source

Thrown at sdks/java/core/src/main/java/org/apache/beam/sdk/schemas/transforms/providers/StringCompiler.java:158

      // Use the error message to derive the actual type.
      for (Diagnostic<?> d : exn.getDiagnostics().getDiagnostics()) {
        String msg = d.getMessage(Locale.ROOT);
        int expectedErrorIndex = msg.indexOf(expectedError);
        if (expectedErrorIndex != -1) {
          String typeSource =
              msg.substring(
                  1 + "incompatible types: ".length() + msg.lastIndexOf('\n', expectedErrorIndex),
                  expectedErrorIndex);
          Class<?> clazz =
              StringCompiler.getClass(
                  "__TypeGuesserHelper__", typeGuesserSource(expression, inputTypes, typeSource));
          for (Method method : clazz.getMethods()) {
            if (method.getName().equals("method")) {
              return method.getGenericReturnType();
            }
          }
          // We should never get here.
          throw new RuntimeException("Unable to locate declared method.");
        }
      }
      // Must have been some other error.
      throw exn;
    }
  }

  private static String typeGuesserSource(
      String expression, Map<String, Type> inputTypes, String returnType) {
    StringBuilder source = new StringBuilder();
    source.append("class __TypeGuesserHelper__ {\n");
    source.append("  private static class BadReturnType { private BadReturnType() {} }\n");
    source.append("  public static " + returnType + " method(\n");
    boolean first = true;
    for (Map.Entry<String, Type> arg : inputTypes.entrySet()) {
      if (first) {
        first = false;
      } else {

View on GitHub (pinned to 12126d8942)

Solutions

  1. Report as a bug to Apache Beam; this is an internal invariant violation
  2. Rewrite the expression in a simpler form that compiles or produces standard type-mismatch diagnostics
  3. Check JDK version compatibility with the Beam version in use
Defensive patterns

Strategy: try-catch

Try / catch

try { guessExpressionType(src, type); }
catch (RuntimeException e) { if ("Unable to locate declared method.".equals(e.getMessage())) { /* report bug / simplify expression */ } else throw e; }

Prevention

When it happens

Trigger: guessExpressionType encounters a type-related CompileException, scans clazz.getMethods() for one literally named "method", and none is found — indicating an unexpected compiler/diagnostic shape.

Common situations: JDK version differences in how synthetic methods are exposed; unusual expression constructs causing diagnostic handling to take an unexpected path.

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


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