{"record":{"id":"2273cf6bbeb4bda4","repo":"apache/beam","slug":"diagnostics","errorCode":null,"errorMessage":"${diagnostics}","messagePattern":"\\$\\{diagnostics\\}","errorType":"exception","errorClass":"CompileException","httpStatus":null,"severity":"error","filePath":"sdks/java/core/src/main/java/org/apache/beam/sdk/schemas/transforms/providers/StringCompiler.java","lineNumber":118,"sourceCode":"\n  // TODO(XXX): swap args?\n  public static <T> Class<T> getClass(String name, String source)\n      throws CompileException, ClassNotFoundException {\n    JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();\n    InMemoryFileManager fileManager =\n        new InMemoryFileManager(compiler.getStandardFileManager(null, null, null));\n    DiagnosticCollector<JavaFileObject> diagnostics = new DiagnosticCollector<>();\n    JavaCompiler.CompilationTask task =\n        compiler.getTask(\n            null,\n            fileManager,\n            diagnostics,\n            ImmutableList.of(\"-classpath\", classpathSupplier.get()),\n            null,\n            Collections.singletonList(new InMemoryFileManager.InputJavaFileObject(name, source)));\n    boolean result = task.call();\n    if (!result) {\n      throw new CompileException(diagnostics);\n    } else {\n      return (Class<T>) fileManager.getClassLoader().loadClass(name);\n    }\n  }\n\n  public static Object getInstance(String name, String source)\n      throws CompileException, ReflectiveOperationException {\n    return getClass(name, source).getDeclaredConstructor().newInstance();\n  }\n\n  public static Type guessExpressionType(String expression, Map<String, Type> inputTypes)\n      throws StringCompiler.CompileException, ClassNotFoundException {\n\n    String expectedError = \"cannot be converted to __TypeGuesserHelper__.BadReturnType\";\n\n    try {\n      StringCompiler.getClass(\n          \"__TypeGuesserHelper__\", typeGuesserSource(expression, inputTypes, \"BadReturnType\"));","sourceCodeStart":100,"sourceCodeEnd":136,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/core/src/main/java/org/apache/beam/sdk/schemas/transforms/providers/StringCompiler.java#L100-L136","documentation":"StringCompiler compiles in-memory Java source with the javax.tools compiler. When task.call() returns false (compilation failed), it throws CompileException carrying the collected Diagnostics (syntax errors, missing symbols, bad classpath). Callers like getInstance wrap it in RuntimeException.","triggerScenarios":"Compiling generated UDF/filter source via getClass() where the source has syntax errors, references unknown symbols/fields, or the classpathSupplier's classpath is wrong/incomplete so imports don't resolve.","commonSituations":"Filter expressions generating code referencing nonexistent schema fields; running in environments where the compiler isn't available or classpath is truncated (shaded/fat jars missing javax.tools dependencies); expression syntax mistakes.","solutions":["Inspect the Diagnostics in the CompileException for the concrete compiler errors","Fix the generated/expression source (check field names against the input schema)","Verify the classpath supplier includes all needed dependencies","Ensure the JDK (not JRE-only runtime) is used so javax.tools is available"],"exampleFix":"// before\nexpression: \"input.nmae\"\n// after\nexpression: \"input.name\"","handlingStrategy":"try-catch","validationCode":"// pre-check: expression references exist in input schema\nif (!inputSchema.hasField(fieldName)) throw new IllegalArgumentException(\"Unknown field: \" + fieldName);","typeGuard":null,"tryCatchPattern":"try { Class<?> c = StringCompiler.getInstance(name, source); }\ncatch (RuntimeException e) {\n  if (e.getCause() instanceof StringCompiler.CompileException) {\n    ((StringCompiler.CompileException) e.getCause()).getDiagnostics().forEach(d -> LOG.error(d));\n  } else throw e;\n}","preventionTips":["Compile expressions in unit tests against the real schema","Ensure the JDK compiler (javax.tools) is available in the runtime image","Verify classpath completeness in shaded deployments"],"tags":["java","apache-beam","compilation","udf"],"backgroundTag":"compilation-failed","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"}