{"record":{"id":"9f7dcbc5877cbd0e","repo":"apache/skywalking","slug":"expected-string-argument-for-extension-function-g","errorCode":null,"errorMessage":"Expected String argument for extension function, got {}","messagePattern":"Expected String argument for extension function, got (.+?)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"oap-server/analyzer/meter-analyzer/src/main/java/org/apache/skywalking/oap/meter/analyzer/v2/compiler/MALMethodChainCodegen.java","lineNumber":186,"sourceCode":"        }\n        sb.append(\");\\n\");\n    }\n\n    /**\n     * Generates a typed argument for an extension function call.\n     * Emits raw literals: {@code 3.0}, {@code 10L}, {@code 3.0F}, {@code 10}.\n     */\n    private void generateExtensionArg(final StringBuilder sb,\n                                       final MALExpressionModel.Argument arg,\n                                       final Class<?> expectedType) {\n        if (expectedType == String.class) {\n            if (arg instanceof MALExpressionModel.StringArgument) {\n                sb.append('\"')\n                  .append(DslJavaSourceText.toLiteral(\n                      ((MALExpressionModel.StringArgument) arg).getValue()))\n                  .append('\"');\n            } else {\n                throw new IllegalArgumentException(\n                    \"Expected String argument for extension function, got \"\n                        + arg.getClass().getSimpleName());\n            }\n        } else if (expectedType == double.class || expectedType == Double.class\n                || expectedType == float.class || expectedType == Float.class\n                || expectedType == long.class || expectedType == Long.class\n                || expectedType == int.class || expectedType == Integer.class) {\n            if (!(arg instanceof MALExpressionModel.ExprArgument)) {\n                throw new IllegalArgumentException(\n                    \"Expected number argument for extension function, got \"\n                        + arg.getClass().getSimpleName());\n            }\n            final MALExpressionModel.Expr expr =\n                ((MALExpressionModel.ExprArgument) arg).getExpr();\n            if (!(expr instanceof MALExpressionModel.NumberExpr)) {\n                throw new IllegalArgumentException(\n                    \"Expected number argument for extension function\");\n            }","sourceCodeStart":168,"sourceCodeEnd":204,"githubUrl":"https://github.com/apache/skywalking/blob/102af09b4a56064e22050dded10e2c52e490d040/oap-server/analyzer/meter-analyzer/src/main/java/org/apache/skywalking/oap/meter/analyzer/v2/compiler/MALMethodChainCodegen.java#L168-L204","documentation":"Thrown by MALMethodChainCodegen.generateExtensionArg when the extension method declares a String parameter but the corresponding MAL argument is not a string literal (not a MALExpressionModel.StringArgument). Only String literals can be spliced into generated Java source for String parameters, so number literals or list literals are rejected.","triggerScenarios":"Extension 'f(SampleFamily, String prefix)' invoked as '.myext::f(100)' or '.myext::f([\"a\",\"b\"])' — the argument node is an ExprArgument/StringListArgument instead of StringArgument. String literals must use double quotes in MAL.","commonSituations":"Using single quotes (MAL filter-closure style) instead of double quotes for string arguments in an extension call; passing a numeric tag value where a string key is expected; forgetting quotes entirely so the parser treats the token as an identifier expression.","solutions":["Pass a double-quoted string literal for every String parameter","If the value is semantically numeric, change the Java parameter to double/int/long instead","Check for stray quotes/typos: 'myext::f(env)' parses as an expression, not a string — write myext::f(\"env\")"],"exampleFix":"# before\nexpr: m.sum([]).myext::withPrefix(100)\n\n# after\nexpr: m.sum([]).myext::withPrefix(\"100\")","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"// pseudo: check each MAL argument kind against the Java param type before compile\nboolean matches(MALExpressionModel.Argument a, Class<?> p) {\n    if (p == String.class) return a instanceof MALExpressionModel.StringArgument;\n    return true; // other checks for numbers/lists\n}","tryCatchPattern":"catch IllegalArgumentException at compile time; include the extension signature in the error report","preventionTips":["Use double quotes for string arguments, single quotes only inside closures","Lint rule files for quoted-number arguments to extension calls"],"tags":["mal","extension","type-mismatch","arguments"],"backgroundTag":null,"analyzedSha":"102af09b4a56064e22050dded10e2c52e490d040","analyzedAt":"2026-08-14T10:47:52.647Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}