{"record":{"id":"6da4834ce2328c7f","repo":"apache/beam","slug":"unable-to-locate-declared-method","errorCode":null,"errorMessage":"Unable to locate declared method.","messagePattern":"Unable to locate declared method\\.","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"sdks/java/core/src/main/java/org/apache/beam/sdk/schemas/transforms/providers/StringCompiler.java","lineNumber":158,"sourceCode":"      // Use the error message to derive the actual type.\n      for (Diagnostic<?> d : exn.getDiagnostics().getDiagnostics()) {\n        String msg = d.getMessage(Locale.ROOT);\n        int expectedErrorIndex = msg.indexOf(expectedError);\n        if (expectedErrorIndex != -1) {\n          String typeSource =\n              msg.substring(\n                  1 + \"incompatible types: \".length() + msg.lastIndexOf('\\n', expectedErrorIndex),\n                  expectedErrorIndex);\n          Class<?> clazz =\n              StringCompiler.getClass(\n                  \"__TypeGuesserHelper__\", typeGuesserSource(expression, inputTypes, typeSource));\n          for (Method method : clazz.getMethods()) {\n            if (method.getName().equals(\"method\")) {\n              return method.getGenericReturnType();\n            }\n          }\n          // We should never get here.\n          throw new RuntimeException(\"Unable to locate declared method.\");\n        }\n      }\n      // Must have been some other error.\n      throw exn;\n    }\n  }\n\n  private static String typeGuesserSource(\n      String expression, Map<String, Type> inputTypes, String returnType) {\n    StringBuilder source = new StringBuilder();\n    source.append(\"class __TypeGuesserHelper__ {\\n\");\n    source.append(\"  private static class BadReturnType { private BadReturnType() {} }\\n\");\n    source.append(\"  public static \" + returnType + \" method(\\n\");\n    boolean first = true;\n    for (Map.Entry<String, Type> arg : inputTypes.entrySet()) {\n      if (first) {\n        first = false;\n      } else {","sourceCodeStart":140,"sourceCodeEnd":176,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/core/src/main/java/org/apache/beam/sdk/schemas/transforms/providers/StringCompiler.java#L140-L176","documentation":"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.","triggerScenarios":"guessExpressionType encounters a type-related CompileException, scans clazz.getMethods() for one literally named \"method\", and none is found — indicating an unexpected compiler/diagnostic shape.","commonSituations":"JDK version differences in how synthetic methods are exposed; unusual expression constructs causing diagnostic handling to take an unexpected path.","solutions":["Report as a bug to Apache Beam; this is an internal invariant violation","Rewrite the expression in a simpler form that compiles or produces standard type-mismatch diagnostics","Check JDK version compatibility with the Beam version in use"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { guessExpressionType(src, type); }\ncatch (RuntimeException e) { if (\"Unable to locate declared method.\".equals(e.getMessage())) { /* report bug / simplify expression */ } else throw e; }","preventionTips":["Keep expressions simple so the type-inference path succeeds","Report reproducible cases to the Beam project","Pin a consistent JDK version"],"tags":["java","apache-beam","internal","reflection"],"backgroundTag":"internal-invariant-violation","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}